Skip to content

Instantly share code, notes, and snippets.

@programmarchy
Last active December 29, 2015 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save programmarchy/7609958 to your computer and use it in GitHub Desktop.
Save programmarchy/7609958 to your computer and use it in GitHub Desktop.
mocha in your serial
var assert = require('assert');
var SerialPort = require('serialport').SerialPort;
var device = require('./config.json')['device'];
describe('opening and closing a serial port', function() {
var serialport;
this.timeout(10000);
before(function() {
serialport = new SerialPort(device);
});
it('should open', function(done) {
serialport.on('open', function() {
done();
});
});
it('should close', function(done) {
serialport.on('close', function() {
done();
});
serialport.close();
});
it('should reopen', function(done) {
serialport.on('open', function() {
done();
});
serialport.open();
});
it('should close again', function(done) {
serialport.on('close', function() {
done();
});
serialport.close();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment