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.

setTimeout is not promisifiable

See original GitHub issue

The simple testcase

const {promisify} = require('util');
const timeout = promisify(setTimeout);

test('should timeout', async () => {
    await timeout(100);
});

works in Node environment, but fails in JSDOM. The difference is that JSDOM gives custom setTimeout implementation, that doesn’t work with Node built-in util.promisify.

Is there a way to make this work? For example, get the original Node’s setTimeout within JSDOM.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
just-boriscommented, Feb 19, 2018

If this is not a bug, then it should show a different error message. Currently it just fails due to test duration timeout.

  ● should timeout

    Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

      at node_modules/jest-jasmine2/build/queue_runner.js:72:21
      at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:633:19)

Maybe if people will find this issue, it already would give them a pointer where to look.

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

setTimeout() - Web APIs - MDN Web Docs
setTimeout () is an asynchronous function, meaning that the timer function will not pause execution of other functions in the functions stack. In ......
Read more >
setTimeout or setInterval? - javascript - Stack Overflow
setTimeout () is a time based code execution method that will execute a script only one time when the interval is reached. It...
Read more >
When should one use setTimeout and what are the ... - Quora
You should never use timeout instead of a promise, they do not serve the same purpose. Promise allows you to associate handlers with...
Read more >
Why setTimeout Does Not Guarantee Time to Execution
I want to go deeper into the asynchronicity of Javascript through a setTimeout example and why it is not a guarantee of time...
Read more >
Datatable not working when I am using settimeout function?
Features like search, sort, pagination, mobile responsive not working. I'm using bootstrap 3, jquery datatable version - 1.10.10.
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