1
我正在为取决于WebSocket库的代码编写Jest测试。禁用Jest setTimeout模拟
websocket库被嘲笑。我想发送消息,等待异步操作完成,然后检查响应。
it('sends a message and gets a response',() => {
processor(ws).sendMessage() // do a bunch of async stuff, call websocket.sendMessage()
setTimeout(() => {
expect(ws.getResponse()).toEqual('all done')
}, 100)
})
不幸的是,因为Jest嘲笑setTimeout,setTimeout失败。如果我运行,超时发生瞬间,所以无法拿起消息。
任何想法如何说服笑话解除setTimeout,或茉莉花解决方法?
玩笑15似乎禁止定时器默认http://facebook.github.io/jest/blog/2016/09/01/jest-15.html嘲笑 –