-
-
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
Expect dies with "ReferenceError: Element is not defined" in "node" test environment #7786
Comments
Wanna send a PR for it? /cc @pedrottimark |
… (clean cherry pick version) (#7995) * Check for existence of `Element` when comparing DOM-nody-things (#7786) * Fall back to deep equality for presumed DOM nodes if `Element` is not in scope (#7786) * Remove IE<9 specific fallback DOM node comparison (#7786) * Check for global DOM `Node` in `isDomNode` (#7786) In a real browser and JSDOM the check will use DOM-Level-3 `Node.isEqualNode` and for everything else a deep equality check should do the trick. * Check that `isEqualNode` is a function and remove duck typing from `isDomNode` (#7786) * Add changelog entry for streamlined DOM node comparisons in `expect` (#7786) * Correct visible PR number in CHANGELOG.md
This code in vue-test-utils.js fails (@vue/test-utils 1.0.0-beta.31). Just installed today released jest 25.1.0 and ts-jest 25.0.0 with vue-jest 3.0.5 (latest)
|
This was fixed in #7995 (included in 24.3.0), and we just forgot to close this issue. @postb99 could you please open up a new issue with reproduction steps? https://repl.it/repls/PureFrightenedIntegers does not reproduce using 24.9.0 or 25.1.0 for me, so I think your issue is different somehow. |
@SimenB Thanks. I just fixed it... By installing jsdom-global as stated here: https://vue-test-utils.vuejs.org/guides/#choosing-a-test-runner despite it should have been set up automatically. So I may open an issue but I think I misread something in documentation... How to find the culprit ? So the relevant packages for my setup are these ones. I write .vue components using typescript, and now Jest runs the test fine. The test code is also written in ts.
jest.config.js:
client.js :
|
remove |
This works well and even speeds up my tests, 4 suites of 37 tests run in 7s instead of 10s when testEnvironment is set to "jsdom". I don't know why I missed the best testEnvironment to set in the documentation, In fact I did a copy-paste from a colleague's project, this was not the best idea. |
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
When running tests with
"testEnvironment": "node"
andexpect
determines via duck typing that it has DOM nodes to compare it throwsReferenceError: Element is not defined
sinceElement
isn't available in Node.To Reproduce
Use
"testEnvironment": "node"
and run this testThe most likely culprit in my opinion is this region where it was determined per duck typing that the things to compare are DOM nodes and then an unguarded
instanceof Element
check is run https://github.com/facebook/jest/blob/master/packages/expect/src/jasmineUtils.js#L134Expected behavior
It should always check that
Element
or any other host object is defined before it is used - so the test above should be green.Link to repl or repo (highly encouraged)
https://repl.it/repls/PureFrightenedIntegers
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: