Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'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. The tests depend on setting up stuff in the DOM, and between tests, the DOM is cleared. 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. Is there a way to cancel or destroy all outstanding promises in-between tests? We are using when.js promises.

like image 824
dandelion Avatar asked Nov 12 '22 17:11

dandelion


1 Answers

when.js supports a cancel() method. You could call it from a afterEach or after block in mocha. You might need to create an array at the top of each mocha file (or as global) to track your outstanding promises.

like image 192
Dan Kohn Avatar answered Nov 15 '22 13:11

Dan Kohn