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

Node.isEqualNode() #656

Closed
jujurocket opened this issue Nov 17, 2022 · 2 comments · Fixed by #696
Closed

Node.isEqualNode() #656

jujurocket opened this issue Nov 17, 2022 · 2 comments · Fixed by #696
Labels
enhancement New feature or request

Comments

@jujurocket
Copy link

jujurocket commented Nov 17, 2022

Is your feature request related to a problem? Please describe.
I wanted to compare two happy-dom nodes in my tests, however the library does not implement the standard
Node.isEqualNode browser method.

Instead I noticed there is a static function (nodeEquals) that implements this functionality in NodeUtility.

The issue is I did not realise this functionality was available in the library until I dug through the source
code, and I had to do this import in order to use it:

import NodeUtility from "happy-dom/lib/nodes/node/NodeUtility"

Describe the solution you'd like
I was wondering if there was some design choice behind this that I haven't considered, or whether it
would be possible to add the method to the INode type, the same way it works in browsers?

Additional context
I am actually using happy-dom to test a web framework I am developing, and it involves comparing
generated HTML trees, hence the above.

The official implementation makes this tricky sometimes because of whitespace between nodes. I have
actually implemented a wrapper function around nodeEquals which first strips the two node trees of
any text nodes only containing whitespace. This makes comparison between two node trees more
meaningful in a test environment for generated HTML.

I'm not sure if the above function would have any use in NodeUtilities as well?


Happy to put in a pull request if any of the above seems desirable.

@gangsthub
Copy link
Contributor

The method in the Node interface according to spec is isEqualNode:

There's also isSameNode. nodeEquals does not exist in the spec, at least at the moment. 🤔

gangsthub added a commit to gangsthub/happy-dom that referenced this issue Jan 23, 2023
capricorn86 added a commit that referenced this issue Jan 28, 2023
#656@minor: Rename `nodeEquals` to `isEqualNode`.
@capricorn86
Copy link
Owner

Thanks for your contribution @gangsthub! 🙂

Your fix has been released.

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v8.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants