Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

jest-fake-timers breaks util.promisify(setTimeout) #9150

Closed
GeorgeBekh opened this issue Nov 8, 2019 · 12 comments 路 Fixed by #9180
Closed

jest-fake-timers breaks util.promisify(setTimeout) #9150

GeorgeBekh opened this issue Nov 8, 2019 · 12 comments 路 Fixed by #9180

Comments

@GeorgeBekh
Copy link

GeorgeBekh commented Nov 8, 2019

馃悰 Bug Report

Jest breaks util.promisify(setTimeout) functionality when using fake timers.
When running code with jest-fake-timers it doesn't have the field setTimeout[util.promisify.custom], even in jest-environment-node (jest-environment-jsdom correctly doesn't have it).

(Updated description to refer to the specific jest-fake-timers problem)

envinfo

  System:
    OS: Linux 4.19 Netrunner 19.08 (Indigo)
    CPU: (12) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
  Binaries:
    Node: 12.12.0 - /bin/node
    npm: 6.12.0 - /bin/npm
  npmPackages:
    jest: ^24.9.0 => 24.9.0
@SimenB
Copy link
Member

SimenB commented Nov 10, 2019

The provided reproduction passes for me

image

Can you set up repl.it, codesandbox or a repository showing the error?

@GeorgeBekh
Copy link
Author

Sure

https://codesandbox.io/s/determined-chandrasekhar-jfey6?fontsize=14
In the right bottom select terminal, click the "Plus" button and run npm run test

@GeorgeBekh
Copy link
Author

@SimenB
懈蟹芯斜褉邪卸械薪懈械

@jeysal
Copy link
Contributor

jeysal commented Nov 11, 2019

Confirmed that setTimeout[util.promisify.custom] is missing in jest-environment-jsdom. But it is there in jest-environment-node. I think this is correct? Most environments with a DOM (browsers) will not have this either, only Node will.
However, it should definitely be there in jest-environment-node when using jest.useFakeTimers() - we should make sure jest-fake-timers supports that.

@SimenB
Copy link
Member

SimenB commented Nov 11, 2019

Ah, I just tested with node. But yeah, util.promisify won't work for the timer in jsdom

@jeysal
Copy link
Contributor

jeysal commented Nov 11, 2019

@GeorgeBekh that should clarify for your case, see docs on how to use different test environments. We could change this issue to be about jest-fake-timers missing the property though :)

@GeorgeBekh
Copy link
Author

GeorgeBekh commented Nov 11, 2019

Thanks I've forgot, about the testEnvironment option.
@jeysal, sure. I'm glad I've helped somehow :)

@jeysal jeysal changed the title Jest breaks util.promisify(setTimeout) jest-fake-timers breaks util.promisify(setTimeout) Nov 11, 2019
@jeysal
Copy link
Contributor

jeysal commented Nov 11, 2019

updated title/description :)

@lourenci
Copy link
Contributor

Is there some assign already? I would like to take a look at this.

@jeysal
Copy link
Contributor

jeysal commented Nov 11, 2019

Go for it! :)

@SimenB
Copy link
Member

SimenB commented Nov 11, 2019

Fixing it for Lolex at the same time would be lovely, if you're up for it 馃檪 Jest will be using Lolex as fake timer implementation as default in v26

sinonjs/fake-timers#223

EDIT: never mind, there's an open PR for Lolex already! sinonjs/fake-timers#227

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants