From 1b831f079fd5faa108451e85ffe911f5ef869fa4 Mon Sep 17 00:00:00 2001 From: Francis Gulotta Date: Tue, 12 Nov 2013 15:37:32 -0500 Subject: [PATCH] Add some basic read tests --- test/serialport-basic.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/serialport-basic.js b/test/serialport-basic.js index 87fd043..c764537 100644 --- a/test/serialport-basic.js +++ b/test/serialport-basic.js @@ -51,6 +51,36 @@ describe('SerialPort', function () { }); + describe('reading data', function () { + + it('emits data events by default', function (done) { + hardware.createPort('/dev/exists'); // clears out any previously written data + var testData = new Buffer("I am a really short string"); + var port = new SerialPort('/dev/exists', function () { + port.once('data', function(recvData) { + expect(recvData).to.eql(testData); + done(); + }); + hardware.emitData('/dev/exists', testData); + }); + }); + + it('calls the dataCallback if set', function (done) { + hardware.createPort('/dev/exists'); // clears out any previously written data + var testData = new Buffer("I am a really short string"); + var opt = { + dataCallback: function (recvData) { + expect(recvData).to.eql(testData); + done(); + } + }; + var port = new SerialPort('/dev/exists', opt, function () { + hardware.emitData('/dev/exists', testData); + }); + }); + + }); + describe('#open', function () { it('passes the port to the bindings', function (done) {