我目前正在使用socket.io进行node.js项目,并进行了一些测试。
https://github.com/jy95/P4ng/blob/master/test/test.js
在像这样的travis上随机构建:https://travis-ci.org/jy95/P4ng/jobs/180385911,我收到了这个错误(请参阅作业日志以获取更多信息):
1) "before each" hook
在beforeEach函数中,我删除了套接字上的所有侦听器:
我之所以这样做,是因为之前的测试回调被触发了(当我对不同的测试用例使用相同的事件时,我得到了错误():多次调用。
beforeEach(function(done) {
// runs before each test in this block
// removes previously listeners to this two sockets (seen in anothers test)
for (let socketTest of [socket1,socket2,socket3,socket4] ) {
if (socketTest !== undefined) {
socketTest.removeAllListeners();
}
}
done();
});
你能解释一下我为什么这么说吗? 谢谢你的帮助。