Skip to content

Commit 57ad4d7

Browse files
committed
#1176@patch: Prevent custom element registration under a different name.
1 parent 1997a86 commit 57ad4d7

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packages/happy-dom/src/custom-element/CustomElementRegistry.ts

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ export default class CustomElementRegistry {
6565
throw new DOMException(`Custom Element: "${localName}" already defined.`);
6666
}
6767

68+
const otherName = this.getName(elementClass);
69+
if (otherName) {
70+
throw new DOMException(`Custom Element already defined as "${otherName}".`);
71+
}
72+
6873
this._registry[localName] = {
6974
elementClass,
7075
extends: options && options.extends ? options.extends.toLowerCase() : null

packages/happy-dom/test/custom-element/CustomElementRegistry.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ describe('CustomElementRegistry', () => {
6363
expect(() => customElements.define('custom-element', CustomElement)).toThrow();
6464
});
6565

66+
it('Throws an error if already registered under a different tag name.', () => {
67+
customElements.define('custom-element', CustomElement);
68+
expect(() => customElements.define('custom-element2', CustomElement)).toThrow();
69+
});
70+
6671
it('Calls observed attributes and set _observedAttributes as a property on the element class.', () => {
6772
customElements.define('custom-element', CustomElement);
6873
expect(CustomElement.observedAttributesCallCount).toBe(1);

0 commit comments

Comments
 (0)