mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
Add an events based unit test to validate that open and close work as expected
This commit is contained in:
parent
a5d0bc6eac
commit
477eabecb4
1 changed files with 28 additions and 0 deletions
|
|
@ -89,4 +89,32 @@ describe ('requiresComPort', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('validate close event', function() {
|
||||
it('opens a port then closes it using events', function(done) {
|
||||
serialPort.list(function(err, ports) {
|
||||
|
||||
chai.assert.isUndefined(err, util.inspect(err));
|
||||
chai.assert.isDefined(ports, 'ports is not defined');
|
||||
chai.assert.isTrue(ports.length > 0, 'no ports found');
|
||||
|
||||
var port = new serialPort.SerialPort(ports.slice(-1)[0].comName, null, false);
|
||||
|
||||
port.on('error', function(err) {
|
||||
chai.assert.fail(util.inspect(err));
|
||||
});
|
||||
|
||||
port.on('open', function() {
|
||||
port.close();
|
||||
});
|
||||
|
||||
port.on('close', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
port.open();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue