Jest: Fake Timer implementation does not have unref method in Node environment

Created on 28 Sep 2017  路  4Comments  路  Source: facebook/jest

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

good first issue

Most helpful comment

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!

All 4 comments

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!

@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 :)

@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 ...

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

Was this page helpful?
0 / 5 - 0 ratings