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

Async test doesn't fail with setTimeout #4019

Closed
kohver opened this issue Jul 12, 2017 · 2 comments
Closed

Async test doesn't fail with setTimeout #4019

kohver opened this issue Jul 12, 2017 · 2 comments

Comments

@kohver
Copy link

kohver commented Jul 12, 2017

I don't know is it expected behaviour or not, but at least this is much counterintuitive. I've spent a few hours to figure out the problem 🙃

Code

test('error', (done) => {
    setTimeout(() => {
        expect(1).toEqual(2);

        done();
    }, 1000);
});

Result

$ yarn run test
yarn run v0.24.5
$ jest
 FAIL  ./index.test.js (5.213s)
  ● error

    Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

      at pTimeout (node_modules/jest-jasmine2/build/queueRunner.js:53:21)
      at ontimeout (timers.js:488:11)
      at tryOnTimeout (timers.js:323:5)
      at Timer.listOnTimeout (timers.js:283:5)

  ✕ error (5008ms)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        6.036s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

But...

this code works well

test('error', (done) => {
    // setTimeout(() => {
        expect(1).toEqual(2);

        done();
    // }, 1000);
});

👉 Repro-repo: https://github.com/kohver/jest-bug

@thymikee
Copy link
Collaborator

This is known issue, it's already worked on here: #4016
Feel free to help to get this PR into next Jest release :)

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

No branches or pull requests

2 participants