Skip to content

Commit

Permalink
Test the write non binding code a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
reconbot committed Aug 8, 2016
1 parent 5616664 commit b340407
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/serialport.js
Expand Up @@ -105,7 +105,7 @@ function SerialPort(path, options, callback) {

stream.Stream.call(this);

if (typeof callback === 'boolean') {
if (typeof callback === 'boolean' || typeof options === 'boolean') {
throw new TypeError('`openImmediately` is now called `autoOpen` and is a property of options');
}

Expand Down
38 changes: 37 additions & 1 deletion test/serialport.js
Expand Up @@ -402,12 +402,48 @@ describe('SerialPort', function() {
describe('#write', function() {
it('errors when the port is not open', function(done) {
var cb = function() {};
var port = new SerialPort('/dev/exists', false, cb);
var port = new SerialPort('/dev/exists', {autoOpen: false}, cb);
port.write(null, function(err) {
assert.instanceOf(err, Error);
done();
});
});

it('writes to the bindings layer', function(done){
var port = new SerialPort('/dev/exists');
port.on('open', function(){
var data = new Buffer('Crazy!');
port.write(data, function(){
var lastWrite = hardware.fds[port.fd].lastWrite;
assert.deepEqual(data, lastWrite);
done();
});
});
});

it('converts strings to buffers', function(done){
var port = new SerialPort('/dev/exists');
port.on('open', function(){
var data = 'Crazy!';
port.write(data, function(){
var lastWrite = hardware.fds[port.fd].lastWrite;
assert.deepEqual(new Buffer(data), lastWrite);
done();
});
});
});

it('converts arrays to buffers', function(done){
var port = new SerialPort('/dev/exists');
port.on('open', function(){
var data = [0,32,44,88];
port.write(data, function(){
var lastWrite = hardware.fds[port.fd].lastWrite;
assert.deepEqual(new Buffer(data), lastWrite);
done();
});
});
});
});

describe('#set', function() {
Expand Down

0 comments on commit b340407

Please sign in to comment.