Description
🚀 Feature Proposal
Provide better errors when async code uses the environment after the test suite finished executing. Something like "This method can't be called because the test suite has finished running. This can happen if you forget to return a promise from a test method that performs asynchronous operations."
Motivation
I just spent a while debugging the following issue:
Cannot read property 'runAllTimers' of null
TypeError: Cannot read property 'runAllTimers' of null
at Object.runAllTimers (/Users/bernie/Documents/GitHub/amara-checkout/node_modules/jest-runtime/build/index.js:969:56)
Caused by a jest.runAllTimers();
in my code. Turns out, this method calls this._environment.fakeTimers.runAllTimers()
, and _environment.fakeTimers
was null because the environment had been torn down, because the test suite had finished executing.
The root cause was that I'd omitted an await
before an async method in a test, and the test method itself was not async.
It would be great to be able to offer an error message that pointed the user to the source of the issue.
Example
n/a
Pitch
Why does this feature belong in the Jest core platform?
It's a tweak to help people use existing functionality correctly.