Skip to content

Commit

Permalink
#1176@patch: Prevent custom element registration under a different name.
Browse files Browse the repository at this point in the history
  • Loading branch information
mash-graz committed Dec 11, 2023
1 parent 1997a86 commit 57ad4d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export default class CustomElementRegistry {
throw new DOMException(`Custom Element: "${localName}" already defined.`);
}

const otherName = this.getName(elementClass);
if (otherName) {
throw new DOMException(`Custom Element already defined as "${otherName}".`);
}

this._registry[localName] = {
elementClass,
extends: options && options.extends ? options.extends.toLowerCase() : null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ describe('CustomElementRegistry', () => {
expect(() => customElements.define('custom-element', CustomElement)).toThrow();
});

it('Throws an error if already registered under a different tag name.', () => {
customElements.define('custom-element', CustomElement);
expect(() => customElements.define('custom-element2', CustomElement)).toThrow();
});

it('Calls observed attributes and set _observedAttributes as a property on the element class.', () => {
customElements.define('custom-element', CustomElement);
expect(CustomElement.observedAttributesCallCount).toBe(1);
Expand Down

0 comments on commit 57ad4d7

Please sign in to comment.