Skip to content

Conversation

@shunkica
Copy link
Collaborator

Closes #880

Spec:
https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttributeNames
https://dom.spec.whatwg.org/#dom-element-getattributenames

Note:
I have found a issue with the serializer in this test:

	test('should handle duplicate qualified names from different namespaces', () => {
		const doc = new DOMImplementation().createDocument(null, 'xml');
		const element = doc.documentElement;

		// Create attributes with same local name but different namespaces
		element.setAttributeNS('http://ns1.example.com', 'test', 'value1');
		element.setAttributeNS('http://ns2.example.com', 'test', 'value2');

		// Should return both attributes
		expect(element.getAttributeNames()).toEqual(['test', 'test']);

		// TODO: there seems to be a bug in the serialization of this document.
		//       It outputs xmlns twice, the serializer should probably automatically prefix the namespaces
	});

When this document is serialized the result is:

<xml xmlns="http://ns1.example.com" test="value1" xmlns="http://ns2.example.com" test="value2"/>

If you do the same in a browser:

const doc = document.implementation.createDocument(null, 'xml');
const element = doc.documentElement;

element.setAttributeNS('http://ns1.example.com', 'test', 'value1');
element.setAttributeNS('http://ns2.example.com', 'test', 'value2');

const serializer = new XMLSerializer();
const xmlStr = serializer.serializeToString(doc);

The serializer automatically adds prefixes:

<xml xmlns:ns1="http://ns1.example.com" ns1:test="value1" xmlns:ns2="http://ns2.example.com" ns2:test="value2"/>

@codecov
Copy link

codecov bot commented Aug 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (master@39fc73e). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #939   +/-   ##
=========================================
  Coverage          ?   95.59%           
=========================================
  Files             ?        8           
  Lines             ?     2204           
  Branches          ?      579           
=========================================
  Hits              ?     2107           
  Misses            ?       97           
  Partials          ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implementation for Element.getAttributeNames is missing

1 participant