-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Event is missing in in setup file under testEnvironment=node, ReferenceError: Event is not defined, Jest 27 #11528 #11705
Comments
Node 15.7 is experimental and not an lts |
@Smrtnyk Unfortunately, yes. Though it's important to note that node 14 does not support Event/EventTarget so it not working there is expected. 15.4 is the minimum that supports Event and EventTarget, and the issue is reproducible from that version and beyond, including node 16.6.1 (latest stable.) I just happened to be using 15.7 but had confirmed that it was not 15.7 specific. Here's a demo: https://github.com/jayphelps/jest-event-demo |
If it's helpful, I did a little bit of digging. I'm not familiar with the jest codebase, but I imagine based on what I can see that it likely creates a new global context and has a hardcoded listed of exposed globals, and Event and EventTarget are just not among them yet because no one has brought it up. Edit: I have confirmed this is the case. |
Makes sense. I see you filed a PR. Have you tried locally with your fix to see if it fixes your issues? |
@Smrtnyk indeed I have. Works great. |
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. |
🐛 Bug Report
The globals Event and EventTarget are missing in any setup file under testEnvironment=node (the default)
#11528 actually caught this but it was closed because presumably it was not known to that maintainer that Node v15.4 got native support for Event and EventTarget.
To Reproduce
Steps to reproduce the behavior:
jest.config.js
setupJest.js
Expected behavior
Event and EventTarget are available globally.
envinfo
The text was updated successfully, but these errors were encountered: