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

BUG: Jest eats exceptions in native DOM events and report tests as green #4400

Closed
Havunen opened this issue Aug 31, 2017 · 8 comments
Closed
Labels

Comments

@Havunen
Copy link

Havunen commented Aug 31, 2017

Hey.

There seems to be bug in Jest when used with JSDom. Errors are not caught during test runs. This can be very dangerous as tests are reported as green even though they failed. I created simple REPL to reproduce the issue.

https://repl.it/K9ij

It seems like this issue is inherited from JSDOM, but as Jest is test runner this should not happen.

@Havunen Havunen changed the title BUG: Jest eats exceptions in native events and report tests as green BUG: Jest eats exceptions in native DOM events and report tests as green Aug 31, 2017
@rknell
Copy link

rknell commented Sep 6, 2017

I made some changes to run the code in the repl and it is failing for me:
https://repl.it/K9ij/4

@Havunen
Copy link
Author

Havunen commented Sep 6, 2017

@rknell The bad example I made is trying to demonstrate issue where exceptions are not caught when they occur off the main thread.

@thymikee
Copy link
Collaborator

Can confirm it happens, and it's both on Jest and JSDOM side. The error is logged to the console in newer version (tested on v11 jest-environment-jsdom-11.0.0) but it's not caught by Jest.

@timrourke
Copy link

+1, I'm seeing similar problems. I ran into this when I discovered that Jest's context was unable to create an instance of a DataTransfer object to support a DragEvent. Took hours to find the issue by carefully wrapping test code in try/catch blocks.

@lobsterhands
Copy link

@timrourke Did you find a solution to the DragEvent DataTransfer issue?

@SimenB
Copy link
Member

SimenB commented Jan 4, 2018

This looked to be fixed in Jest 22, @Havunen can you please test again?

The logging is quite atrocious, but it at least fails.

Error: Uncaught [ReferenceError: asasasasassaasasasasasasas is not defined]
    at reportException (/Users/simbekkh/repos/framsie-dashboard/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
    at invokeEventListeners (/Users/simbekkh/repos/framsie-dashboard/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:209:9)
    at HTMLDivElementImpl._dispatch (/Users/simbekkh/repos/framsie-dashboard/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
    at HTMLDivElementImpl.dispatchEvent (/Users/simbekkh/repos/framsie-dashboard/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
    at HTMLDivElementImpl.dispatchEvent (/Users/simbekkh/repos/framsie-dashboard/node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
    at HTMLDivElement.dispatchEvent (/Users/simbekkh/repos/framsie-dashboard/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:143:21)
    at add (/Users/simbekkh/repos/framsie-dashboard/lib/server-impl.test.js:18:9)
    at Object.<anonymous> (/Users/simbekkh/repos/framsie-dashboard/lib/server-impl.test.js:25:16)
    at Object.asyncFn (/Users/simbekkh/repos/framsie-dashboard/node_modules/jest-jasmine2/build/jasmine_async.js:124:345)
    at resolve (/Users/simbekkh/repos/framsie-dashboard/node_modules/jest-jasmine2/build/queue_runner.js:51:12) ReferenceError: asasasasassaasasasasasasas is not defined
    at HTMLDivElement.failure (/Users/simbekkh/repos/framsie-dashboard/lib/server-impl.test.js:7:5)
    at HTMLDivElement.el.addEventListener.event (/Users/simbekkh/repos/framsie-dashboard/node_modules/jsdom/lib/jsdom/living/helpers/create-event-accessor.js:31:30)
    at invokeEventListeners (/Users/simbekkh/repos/framsie-dashboard/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:193:27)
    at HTMLDivElementImpl._dispatch (/Users/simbekkh/repos/framsie-dashboard/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
    at HTMLDivElementImpl.dispatchEvent (/Users/simbekkh/repos/framsie-dashboard/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
    at HTMLDivElementImpl.dispatchEvent (/Users/simbekkh/repos/framsie-dashboard/node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
    at HTMLDivElement.dispatchEvent (/Users/simbekkh/repos/framsie-dashboard/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:143:21)
    at add (/Users/simbekkh/repos/framsie-dashboard/lib/server-impl.test.js:18:9)
    at Object.<anonymous> (/Users/simbekkh/repos/framsie-dashboard/lib/server-impl.test.js:25:16)
    at Object.asyncFn (/Users/simbekkh/repos/framsie-dashboard/node_modules/jest-jasmine2/build/jasmine_async.js:124:345)
    at resolve (/Users/simbekkh/repos/framsie-dashboard/node_modules/jest-jasmine2/build/queue_runner.js:51:12)
    at new Promise (<anonymous>)
    at mapper (/Users/simbekkh/repos/framsie-dashboard/node_modules/jest-jasmine2/build/queue_runner.js:40:274)
    at promise.then (/Users/simbekkh/repos/framsie-dashboard/node_modules/jest-jasmine2/build/queue_runner.js:83:39)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
 FAIL  lib/server-impl.test.js
  add
    ✕ should add two numbers (10ms)

  ● add › should add two numbers

    ReferenceError: asasasasassaasasasasasasas is not defined

       5 |     console.info('volkswagen style...');
       6 |     // any kind of crazy code can be written here....
    >  7 |     asasasasassaasasasasasasas();
       8 |     ccacqwcwqwqwcqwcqwcqwqccwqwqcwqcwqcwqcwqcwqcwqcwqc();
       9 |     throw Error('still not failing....')
      10 | }

      at HTMLDivElement.failure (lib/server-impl.test.js:7:5)
      at HTMLDivElement.el.addEventListener.event (node_modules/jsdom/lib/jsdom/living/helpers/create-event-accessor.js:31:30)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:193:27)
      at HTMLDivElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
      at HTMLDivElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
      at HTMLDivElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
      at HTMLDivElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:143:21)
      at add (lib/server-impl.test.js:18:9)
      at Object.<anonymous> (lib/server-impl.test.js:25:16)

  console.info lib/server-impl.test.js:5
    volkswagen style...

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        1.245s

My guess that it got fixed with #4669 (and #4767)

@Havunen
Copy link
Author

Havunen commented Jan 11, 2018

Yeah thanks guys. This is now working as expected! 👍

@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

No branches or pull requests

6 participants