为什么我的茉莉花unit testing不等待“完成”?
我在我的节点应用程序中testing…
it('will call done', function(done) { myObj.fn(function(){ done(); } });
和代码….
myObj.fn = function(success){ setTimeout(2000000000,success); }
当我运行testing时,我在输出中得到这个…
-MacBook-Pro:torus-pqdata user$ npm test > torus-pqdata@0.0.0 test /Stuff/code bases/2015/torus-pqdata > jasmine-node specs/
但是,正如你所看到的unit testing只是退出没有失败,但我需要它超时(我试图模拟悬挂的东西)。 我如何让它超时?
在setTimeout中交换参数:
myObj.fn = function(success){ setTimeout(success, 200000000); }
以下是MDN的一些参考资料: https : //developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout