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

expect: Compare DOM nodes even if there are multiple Node classes #8064

Merged
merged 4 commits into from
Mar 8, 2019

Conversation

pedrottimark
Copy link
Contributor

Summary

The solution in #7995 was an unintended breaking change for tests that compare DOM nodes which are not instanceof the Node class that in the global scope:

  • An actual case is JSDOM.fragment returns fragment which has different base class than Node class from --env=jsdom option
  • A plausible case is in-browser testing children of an iframe element

Replace isDomNode function with a possibility that we discussed in #7791 (comment)

/cc @mfeineis

Although this change makes it possible to compare two nodes which have the same base class, it wasn’t and still isn’t possible to compare two nodes which have different base classes because the isEqualNode method throws TypeError: Failed to execute 'isEqualNode' on 'Node': parameter 1 is not of type 'Node'.

Test plan

Existing tests pass

Added toEqual-dom.test.js file as spec for:

I didn’t add test of multiple Node classes because it might break in future jsdom versions

@codecov-io
Copy link

Codecov Report

Merging #8064 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8064      +/-   ##
==========================================
+ Coverage   62.36%   62.37%   +0.01%     
==========================================
  Files         262      262              
  Lines       10312    10313       +1     
  Branches     2491     2491              
==========================================
+ Hits         6431     6433       +2     
  Misses       3307     3307              
+ Partials      574      573       -1
Impacted Files Coverage Δ
packages/expect/src/jasmineUtils.ts 85.84% <100%> (+1.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e32813...c5c35e7. Read the comment docs.

@mfeineis
Copy link
Contributor

mfeineis commented Mar 6, 2019

Interesting, I didn't think of cases where nodes may have different base classes and the tests obviously also didn't check for that 😄 - at least now that's part of the official API documented by the test suite.

@pedrottimark
Copy link
Contributor Author

The new tests make sure that Jest works for ordinary DOM and doesn’t regress for your use case.

Although we confirmed the breaking case in local tests, it seemed too brittle for Jest repo.

@github-actions
Copy link

This pull request 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 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants