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

runOnlyPendingTimers running nested timer under setImmediate #3048

Closed
felipeochoa opened this issue Mar 2, 2017 · 1 comment · Fixed by #4608
Closed

runOnlyPendingTimers running nested timer under setImmediate #3048

felipeochoa opened this issue Mar 2, 2017 · 1 comment · Fixed by #4608
Labels

Comments

@felipeochoa
Copy link
Contributor

The following test case is failing on 19.0.2 on node 6.9.6, 7.50, and 7.7.1

it("only runs currently scheduled tasks [immediate]", function() {
    jest.useFakeTimers();
    let c1 = false,
        c2 = false;
    setImmediate(() => {
        c1 = true;
        setTimeout(() => c2 = true, 100 * 1000);
    });
    expect(c1).toBe(false);
    expect(c2).toBe(false);
    jest.runOnlyPendingTimers();
    expect(c1).toBe(true);
    expect(c2).toBe(false);  // <--------- this check fails
});

I'm not sure whether the setImmediate should be run by runOnlyPendingTimers or not (the docs say it runs "macro-tasks"), but the inner timeout should definitely not be run.

As a point of comparison, the following test passes:

it("only runs currently scheduled tasks [timeout]", function() {
    jest.useFakeTimers();
    let c1 = false,
        c2 = false;
    setTimeout(() => {  // <----- changed this line
        c1 = true;
        setTimeout(() => c2 = true, 100 * 1000);
    });
    expect(c1).toBe(false);
    expect(c2).toBe(false);
    jest.runOnlyPendingTimers();
    expect(c1).toBe(true);
    expect(c2).toBe(false);
});

You can see this live at https://repl.it/GFHY/2

@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.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants