question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
jinxaccommented, Jul 9, 2018

@thymikee ok so adding require("bezier"); before my Animated Component tests looks like the way handle this.

0reactions
github-actions[bot]commented, May 12, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found