简体   繁体   English

在mocha.js测试超时后,'Zombie承诺'继续

[英]'Zombie promises' continuing after a mocha.js test timeout

I'm using a testing setup with Mocha.js and a lot of promises within the tests. 我正在使用Mocha.js的测试设置和测试中的许多承诺。 The tests depend on setting up stuff in the DOM, and between tests, the DOM is cleared. 测试依赖于在DOM中设置内容,在测试之间,DOM被清除。 However, sometimes the tests run slowly and time out. 但是,有时测试运行缓慢且超时。 In this case, their promises continue to execute but the DOM is cleared before the next test, so the promise may incorrectly throw errors into the next test. 在这种情况下,它们的promise会继续执行,但DOM会在下一次测试之前被清除,因此promise可能会错误地将错误输入到下一个测试中。 Is there a way to cancel or destroy all outstanding promises in-between tests? 有没有办法取消或销毁测试之间所有未完成的承诺? We are using when.js promises. 我们正在使用when.js的承诺。

when.js supports a cancel() method . when.js支持cancel() 方法 You could call it from a afterEach or after block in mocha. 您可以从afterEach或在mocha中的块after调用它。 You might need to create an array at the top of each mocha file (or as global) to track your outstanding promises. 您可能需要在每个mocha文件的顶部(或作为全局)创建一个数组来跟踪您未完成的承诺。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM