Skip to content

Make sure that jest tests fail if an error is thrown within a jsdom event handlerΒ #8260

@sophiebits

Description

@sophiebits

In a few situations in our unit tests, we use .dispatchEvent on a jsdom DOM node in order to use the jsdom event system:

instance.a.dispatchEvent(inputEvent);

But it appears that if the event handler throws (ex: change the onChange handler in that test to throw), then the error is silently ignored and does not cause the test to fail.

jsdom does make some attempt to report an error:

https://github.com/tmpvar/jsdom/blob/9.8.3/lib/jsdom/living/events/EventTarget-impl.js#L235

We should hook into this in our jest config (scripts/jest/test-framework-setup.js) and see if we can fail any test that triggers this exception behavior. From the implementation of reportException it looks like we might be able to do an onerror handler; if that doesn't work then hooking into their "virtual console" may be possible.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions