I'd like to test that a socket got opened. For this I tried to supply a chai spy, to see that the connection callback got called. Everything looks fine, I got the code sample from chai-spi docs. But the test fails. The strange this is that I can see in the output log, that the function got called.
The only thing I can think of is, that the assertion got called before the callback. Anyway I'm new to node, any help appreciated.
var chai = require('chai');
var spies = require('chai-spies');
var should = chai.should();
var expect = chai.expect;
var io = require('socket.io-client');
chai.use(spies);
function onConnect(socket) {
console.log('monkey');
}
describe('Socket', function(done) {
it('Opens the socket', function(done) {
var spy = chai.spy(onConnect);
var socket = io.connect('http://localhost:3000');
socket.on('connect', spy);
//expect(spy).to.have.been.called();
spy.should.have.been.called();
done();
});
});
Test output:
2) Socket Opens the socket:
AssertionError: expected { Spy } to have been called
at Context.<anonymous> (test/test.socket.js:19:30)
monkey
Aucun commentaire:
Enregistrer un commentaire