我的测试
为了便于阅读,我删除了一些代码。
我发消息hello
给client1
:
client1.emit('chat_to_user', {user: 'user2', message: 'hello'})
和client2监听chat_to_user
事件。
it('chat', function(done) {
client2.socket.on('chat_to_user', function(data) {
data.message.should.equal('hello')
done()
});
});
上面这个测试很好,测试通过了。
改变我的测试,它应该抛出错误(但不是)
但是当我更改 client2 代码时:
it('chat', function(done) {
client2.socket.on('chat_to_user', function(data) {
//notice here! the `data.message` should equal `hello`
data.message.should.equal('i am fine')
done()
});
});
当我运行测试时,它应该会抛出一个错误,并告诉我错误原因,如下所示:
AssertionError: expected 'i am fine' to be 'hello'
+ expected - actual
+"i am fine"
-"hello"
但它没有抛出错误原因,它只是抛出一个超时错误:
Error: timeout of 5000ms exceeded
那么,如何使用 Socket.io 测试抛出错误原因?
我正在使用 socket.io 1.0