Tests: Fix #start() test - rewrite, use updated sample data

Rewriting the "#start()" test so it makes sense, with sample data based on the example in `pcsc.js`.
This commit is contained in:
Roy de Jong
2019-06-06 17:39:03 +02:00
parent 842ea1dbea
commit 236b76c69b

View File

@@ -3,59 +3,32 @@ const sinon = require('sinon');
const pcsc = require('../lib/pcsclite'); const pcsc = require('../lib/pcsclite');
describe('Testing PCSCLite private', function() { describe('Testing PCSCLite private', function() {
describe('#start()', function() { describe('#start()', function() {
before(function() {
this.clock = sinon.useFakeTimers();
});
it('#start() stub', function(done) { it('#start() stub', function(done) {
var self = this;
var p = pcsc(); var p = pcsc();
var stub = sinon.stub(p, 'start').callsFake(function(my_cb) {
var times = 0;
setInterval(function() {
switch (++ times) {
case 1:
my_cb(undefined, Buffer.from("MyReader\0"));
self.clock.tick(1000);
break;
case 2: try {
my_cb(undefined, Buffer.from("MyReader")); var stub = sinon.stub(p, 'start').callsFake(function(startCb) {
break; startCb(undefined, Buffer.from("ACS ACR122U PICC Interface\u0000ACS ACR122U PICC Interface 01\u0000\u0000"));
case 3:
my_cb(undefined, Buffer.from("MyReader1\0MyReader2\0"));
break;
}
}, 1000);
self.clock.tick(1000);
}); });
var times = 0; var readerHit = 0;
p.on('reader', function(reader) { p.on('reader', function(reader) {
reader.close(); reader.close();
switch (++ times) {
switch (++readerHit) {
case 1: case 1:
reader.name.should.equal("MyReader"); reader.name.should.equal("ACS ACR122U PICC Interface");
break; break;
case 2: case 2:
reader.name.should.equal("MyReader1"); reader.name.should.equal("ACS ACR122U PICC Interface 01");
break;
case 3:
reader.name.should.equal("MyReader2");
p.close();
done(); done();
break; break;
} }
}); });
}); } finally {
p.close();
after(function() { }
this.clock.restore();
}); });
}); });
}); });