Node.js 开玩笑不';t在回调中完成对done()的测试
我有两个异步测试,其中一个运行良好,第二个在超时之前调用异步回调失败。实际上,我想它确实调用了Node.js 开玩笑不';t在回调中完成对done()的测试,node.js,socket.io,jestjs,Node.js,Socket.io,Jestjs,我有两个异步测试,其中一个运行良好,第二个在超时之前调用异步回调失败。实际上,我想它确实调用了done()回调,但一切都继续工作 第一个(正确)如下所示: it('User should be verified', done => { const wsClient = require('socket.io-client')('http://localhost:7575/') function callback({ user, isNameTaken })
done()
回调,但一切都继续工作
第一个(正确)如下所示:
it('User should be verified', done => {
const wsClient = require('socket.io-client')('http://localhost:7575/')
function callback({ user, isNameTaken }) {
expect(isNameTaken).toBe(false)
expect(typeof user.id).toBe('string')
expect(user.name).toBe('Sam')
done()
}
wsClient.emit(VERIFY_USER, 'Sam', callback)
})
第二个一个(不正确):
第二次测试的控制台输出:
FAIL test/integration/loggingIn.spec.js (7.398s)
● Console
console.log test/integration/loggingIn.spec.js:12
BEFORE
console.log test/integration/loggingIn.spec.js:79
============ CALLBACK A =============== 2018-12-06T12:00:17.500Z
console.log test/integration/loggingIn.spec.js:69
============ CALLBACK B =============== 2018-12-06T12:00:17.520Z
console.log test/integration/loggingIn.spec.js:70
{ user: null, isNameTaken: true }
console.log test/integration/loggingIn.spec.js:71
{ done: { [Function: next] fail: [Function] } }
console.log test/integration/loggingIn.spec.js:75
============ CALLBACK B After done() =============== 2018-12-06T12:00:17.530Z
● User connection tests › Do not allow duplicate nicknames
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
日志输出显示已触发回调,并且应调用done()
。我不知道我的考试有什么问题,或是开玩笑,或是。。。嗯,这里怎么了
UPD:这是存储库:可能是因为测试完成后套接字IO没有退出。检查这个:你解决过这个问题吗?我在使用套接字时也看到了它。
FAIL test/integration/loggingIn.spec.js (7.398s)
● Console
console.log test/integration/loggingIn.spec.js:12
BEFORE
console.log test/integration/loggingIn.spec.js:79
============ CALLBACK A =============== 2018-12-06T12:00:17.500Z
console.log test/integration/loggingIn.spec.js:69
============ CALLBACK B =============== 2018-12-06T12:00:17.520Z
console.log test/integration/loggingIn.spec.js:70
{ user: null, isNameTaken: true }
console.log test/integration/loggingIn.spec.js:71
{ done: { [Function: next] fail: [Function] } }
console.log test/integration/loggingIn.spec.js:75
============ CALLBACK B After done() =============== 2018-12-06T12:00:17.530Z
● User connection tests › Do not allow duplicate nicknames
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.