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

throw in setTimeout/setInterval is ignored #2685

Closed
capaj opened this issue Jan 24, 2017 · 5 comments
Closed

throw in setTimeout/setInterval is ignored #2685

capaj opened this issue Jan 24, 2017 · 5 comments

Comments

@capaj
Copy link
Contributor

capaj commented Jan 24, 2017

describe('no', function () {
  it('fucks up', function (done) {
    setTimeout(() => {
      throw new Error('nooooo')
    }, 10)
  })
})

running in jest, I get:

 FAIL  util/promise-timeout.spec.js (5.203s)
  ● no › fucks up

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

      at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:477:19)
      at ontimeout (timers.js:365:14)
      at tryOnTimeout (timers.js:237:5)
      at Timer.listOnTimeout (timers.js:207:5)

  no
    ✕ fucks up (5003ms)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        5.629s
Ran all test suites matching "promise-timeout".

Now compare that to how mocha handles it:

capaj@capaj-i7-4771:~/git_projects/be/chat-api$ mocha /home/capaj/git_projects/be/chat-api/util/promise-timeout.spec.js


  no
    1) fucks up


  0 passing (17ms)
  1 failing

  1) no fucks up:
     Uncaught Error: nooooo
      at Timeout.setTimeout [as _onTimeout] (util/promise-timeout.spec.js:43:13)

This is bug right? Please tell me this is a bug, not a feature.

@capaj capaj changed the title throw in setTimeout is ignored throw in setTimeout/setInterval is ignored Jan 24, 2017
@thymikee
Copy link
Collaborator

I think this is already addressed somewhere here #1873 (comment) and here #2059.

There are workarounds for that, but we should provide much better DX on this.

@capaj
Copy link
Contributor Author

capaj commented Jan 24, 2017

@thymikee only workaround I found was #2059 (comment) and that's quite ugly.

IMHO Jest should fall in line with how every other spec runner handles this.

@cpojer
Copy link
Member

cpojer commented Jan 24, 2017

@capaj please send us a PR to address this.

@capaj
Copy link
Contributor Author

capaj commented Jan 28, 2017

trying it on the latest master it seems to be working properly and throwing the error both with fake and regular timers

@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

3 participants