Skip to content

Commit

Permalink
Complete SerialDataSourceProvider tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielwippermann committed Feb 15, 2014
1 parent 57c7c6d commit e1edc2f
Showing 1 changed file with 98 additions and 3 deletions.
101 changes: 98 additions & 3 deletions test/specs/serial-data-source-provider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@



var SerialDataSourceProvider = require('./resol-vbus').SerialDataSourceProvider;
var Q = require('q');
var serialport = require('serialport');


var vbus = require('./resol-vbus');
var testUtils = require('./test-utils');



var SerialDataSource = vbus.SerialDataSource;
var SerialDataSourceProvider = vbus.SerialDataSourceProvider;



Expand All @@ -12,12 +22,97 @@ describe('SerialDataSourceProvider', function() {
describe('constructor', function() {

it('should be a constructor function', function() {
expect(SerialDataSourceProvider).to.be.a('function');
expect(SerialDataSourceProvider)
.to.be.a('function')
.that.has.a.property('extend')
.that.is.a('function');
});

});

describe('#discoverDataSources', function() {

it('should be a method', function() {
expect(SerialDataSourceProvider.prototype)
.to.have.a.property('discoverDataSources')
.that.is.a('function');
});

it('should work correctly', function(done) {
var originalList = serialport.list;

var ports = [
{ comName: 'SERIALPORT1' },
{ comName: 'SERIALPORT2' },
];

serialport.list = sinon.spy(function(callback) {
callback(null, ports);
});

var dsp = new SerialDataSourceProvider();

testUtils.performAsyncTest(done, function() {
return Q.fcall(function() {
var promise = dsp.discoverDataSources();

return testUtils.expectPromise(promise);
}).then(function(dataSources) {
expect(dataSources)
.to.be.an('array')
.lengthOf(ports.length);
}).finally(function() {
serialport.list = originalList;
});
});
});

it('should reject if an error occurs', function(done) {
var originalList = serialport.list;

serialport.list = sinon.spy(function(callback) {
callback(new Error('ERROR'));
});

var dsp = new SerialDataSourceProvider();

var callback = function(err) {
if (err) {
done();
} else {
done(new Error('Should have thrown'));
}
};

testUtils.performAsyncTest(callback, function() {
return Q.fcall(function() {
var promise = dsp.discoverDataSources();

return testUtils.expectPromise(promise);
}).finally(function() {
serialport.list = originalList;
});
});
});

});

xit('should perform tests...', function() {
describe('#createDataSource', function() {

it('should be a method', function() {
expect(SerialDataSourceProvider.prototype)
.to.have.a.property('createDataSource')
.that.is.a('function');
});

it('should work correctly', function() {
var dsp = new SerialDataSourceProvider();

var ds = dsp.createDataSource();

expect(ds)
.to.be.instanceOf(SerialDataSource);
});

});

Expand Down

0 comments on commit e1edc2f

Please sign in to comment.