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

Elment.attributes does not implement the NamedNodeMap interface #308

Closed
sondr opened this issue Nov 24, 2021 · 8 comments · Fixed by #626
Closed

Elment.attributes does not implement the NamedNodeMap interface #308

sondr opened this issue Nov 24, 2021 · 8 comments · Fixed by #626
Labels
enhancement New feature or request high priority

Comments

@sondr
Copy link

sondr commented Nov 24, 2021

I was trying to replace JSDOM with Happy DOM and the app was failing to run something akin to:

const element = document.createElement('div');
const someAttribute = document.createAttribute('someattribute');
element.attributes.setNamedItem(someAttribute);

I see the current implementation is:

readonly attributes: { [k: string]: Attr | number };

Is there any chance there will be a switch to NamedNodeMap in the future?

@capricorn86
Copy link
Owner

Hi @sondr! 🙂

Yes I will add support for this as soon as possible. This will probably come in pretty soon as it is fairly easy to implement support for.

@capricorn86 capricorn86 added the enhancement New feature or request label Jan 25, 2022
@urkle
Copy link

urkle commented Feb 25, 2022

This is needed to support vue-test-utils (1.x) as it uses attributes.length and attributes.item(#)

@brattonross
Copy link

brattonross commented Apr 1, 2022

I ran into an issue related to this when running tests with axe-core. It looks like in their code there are a couple of if statements that do a check along the lines of:

if (attributes instanceof window.NamedNodeMap) {
 // ...
}

This results in the error Right-hand side of 'instanceof' is not an object being thrown, and the tests failing.

I think this is a little different to the original issue since this is concerning window and not an element, although I could be wrong

@Archon-
Copy link

Archon- commented May 23, 2022

Code such as this in Jest tests:

expect(wrapper.find('.button').attributes().disabled).toEqual('disabled')

Throw an error: TypeError: attributes.item is not a function. Seems like it's the same issue. Is this in active development? Is there anything I could help with?

@matt-smarsh
Copy link

This issue seems to be the last one preventing a drop-in replacement from jsdom. I'm using vitest & @vue/test-utils@1 and I can't switch because of the error TypeError: attributes.item is not a function which is thrown from within @vue/test-utils and is unavoidable.

@flip111
Copy link

flip111 commented Oct 10, 2022

I switched from jsdom to happy-dom for performance and jsdom lack of ESM. I can't get my nodejs program to run cross-platform without this feature.

@jledentu
Copy link
Contributor

@capricorn86 Don't know if you've worked on this, otherwise I can help to write a PR.

jledentu added a commit to jledentu/happy-dom that referenced this issue Oct 18, 2022
jledentu added a commit to jledentu/happy-dom that referenced this issue Oct 18, 2022
capricorn86 pushed a commit to jledentu/happy-dom that referenced this issue Oct 18, 2022
capricorn86 added a commit to jledentu/happy-dom that referenced this issue Oct 18, 2022
capricorn86 added a commit that referenced this issue Oct 18, 2022
#308@minor: Implement NamedNodeMap and use it for Element.attributes
@capricorn86
Copy link
Owner

Thank you contributing @jledentu! 🙂

There is a fix in now.

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v7.6.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 high priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants