Jest issue. FakeTimers: clearTimeout was invoked to clear a native timer instead of one created by this library

Viewed 2803

After the update of Node.js from version 14 to version 16, we've got a lot of failed tests on bitbucket CI/CD pipelines. Locally tests pass.

Seems like the problem in timers, cause the first error message says: "FakeTimers: clearTimeout was invoked to clear a native timer instead of one created by this library. To automatically clean-up native timers, use shouldClearNativeTimers". After that, a bunch of test fails.

After adding "--runInBand" parameter for jest it solves the issue, but it's not an ideal approach.

Will appreciate any help.

2 Answers

The answer from @dagadm did not work for me. It turns out I was using jest 26 which was the problem. The following fixed it for me.

npm i --save-dev jest@27 ts-jest@27 @types/jest@27

Then, of course, I ran into the "Test functions cannot both take a 'done' callback" issue which is solved here. I had to remove all my done functions from async tests.

Related