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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fake Timer implementation does not have unref method in Node environment #4559

Closed
vkrol opened this issue Sep 28, 2017 · 5 comments · Fixed by #4622
Closed

Fake Timer implementation does not have unref method in Node environment #4559

vkrol opened this issue Sep 28, 2017 · 5 comments · Fixed by #4622

Comments

@vkrol
Copy link
Contributor

vkrol commented Sep 28, 2017

Do you want to request a feature or report a bug?
Bug.

What is the current behavior?
The fake Timer implementation does not have unref method in Node environment.

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

test("fake Time implementation does not have unref method", () => {
    const realTimer = setTimeout(() => {});
    expect(typeof realTimer.unref).toEqual("function");

    jest.useFakeTimers();

    const fakeTimer = setTimeout(() => {});
    expect(typeof fakeTimer.unref).toEqual("undefined");
});

https://repl.it/Lm5x

What is the expected behavior?
Fake Timer implementation should have unref method in Node environment.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Node - 8.5.0
Yarn - 1.1.0
Jest - 21.2.0

@cpojer
Copy link
Member

cpojer commented Sep 28, 2017

Oh yeah, we don't implement the same Timer interface. Would you be willing to add this functionality to FakeTimers, and sending a PR with tests? Thanks!

@vkrol
Copy link
Contributor Author

vkrol commented Sep 28, 2017

@cpojer thanks for the quick response! I'll definitely try, but I'm not sure that I will succeed, so if someone else wants to implement this, then I will be glad :)

@skrivle
Copy link
Contributor

skrivle commented Oct 6, 2017

@cpojer I'm trying to come up with a PR for this but since I'm new to the codebase I'm wondering if there's a standard way to determine the environment in jest (node/jsdom). Or should I execute a setTimeout in order to decide on the return type? This is how sinon.js handles it ...

@cpojer
Copy link
Member

cpojer commented Oct 6, 2017

I guess FakeTimers is created by the env, so jest-environment-node could configure FakeTimers to use node's API.

@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 13, 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