Promises with set Timeout don't resolve properly in jest 23.0.x
See original GitHub issue🐛 Bug Report
I was using promise resolution with setTimeout in one of my test cases and seems like promise are not resolving at all. I had opened this bug earlier here https://github.com/facebook/jest/issues/6658 but solution given here is working on Jest v22.1.2
. My environment is different and I cant comment in the earlier issue thread as it was marked for commenting only by collaborators.
To Reproduce
it("should show error UI", async () => {
await new Promise(resolve => setTimeout(resolve, 0));
});
Expected behavior
Test should end
Run npx envinfo --preset jest
Paste the results here:
System:
OS: macOS Sierra 10.12.6
CPU: x64 Intel(R) Core(TM) i5 CPU M 540 @ 2.53GHz
Binaries:
Node: 8.11.1 - /usr/local/bin/node
Yarn: 1.3.2 - /usr/local/bin/yarn
npm: 5.6.0 - /usr/local/bin/npm
npmPackages:
jest: ^23.3.0 => 23.3.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
Jest: Timer and Promise don't work well. (setTimeout and ...
setTimeout () does not run a second time since the rest of ... But calling await Promise.resolve() only seems to resolve one pending...
Read more >Timer Mocks - Jest
This is replacing the original implementation of setTimeout() and other timer functions. Timers can be restored to their normal behavior with ...
Read more >Node.js v19.3.0 Documentation
Promise execution tracking; JavaScript embedder API ... No Addon Loading; No require.resolve; No NODE_PATH; No require.extensions; No require.cache.
Read more >Promises chaining - The Modern JavaScript Tutorial
This is not chaining. For example: let promise = new Promise(function(resolve, reject) { setTimeout(() => resolve(1), 1000); } ...
Read more >Handling setTimeout & setInterval in jest/Enzyme - Medium
My assumption is that the setTimeout / setInterval function internally resolve promises and when we use the flush promised function that ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@thymikee ok so adding
require("bezier");
before my Animated Component tests looks like the way handle this.This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.