|
7 | 7 | import {suite} from 'uvu'; |
8 | 8 | // eslint-disable-next-line import/extensions |
9 | 9 | import * as assert from 'uvu/assert'; |
10 | | -import {HTMLElement} from '@lit-labs/ssr-dom-shim'; |
| 10 | +import {customElements, HTMLElement} from '@lit-labs/ssr-dom-shim'; |
11 | 11 |
|
12 | 12 | const test = suite('Element Shim'); |
13 | 13 |
|
@@ -45,4 +45,32 @@ test('setAttribute silently casts values to a string', () => { |
45 | 45 | assert.equal(shimmedEl.getAttribute('tomato'), '[object Object]'); |
46 | 46 | }); |
47 | 47 |
|
| 48 | +test('localName and tagName should be available with constructor from customElements registry', () => { |
| 49 | + const elementName = 'lit-test-registry'; |
| 50 | + customElements.define(elementName, class extends HTMLElement {}); |
| 51 | + const LitTestRegistry = customElements.get(elementName)!; |
| 52 | + |
| 53 | + const shimmedEl = new LitTestRegistry(); |
| 54 | + assert.equal(shimmedEl.localName, elementName); |
| 55 | + assert.equal(shimmedEl.tagName, elementName.toUpperCase()); |
| 56 | +}); |
| 57 | + |
| 58 | +test('localName and tagName should be available when registering with customElements', () => { |
| 59 | + const elementName = 'lit-test-local'; |
| 60 | + class LitTestLocal extends HTMLElement {} |
| 61 | + customElements.define(elementName, LitTestLocal); |
| 62 | + |
| 63 | + const shimmedEl = new LitTestLocal(); |
| 64 | + assert.equal(shimmedEl.localName, elementName); |
| 65 | + assert.equal(shimmedEl.tagName, elementName.toUpperCase()); |
| 66 | +}); |
| 67 | + |
| 68 | +test('localName and tagName usage should return undefined if not registered', () => { |
| 69 | + class LitTestUnregistered extends HTMLElement {} |
| 70 | + |
| 71 | + const shimmedEl = new LitTestUnregistered(); |
| 72 | + assert.equal(shimmedEl.localName, undefined); |
| 73 | + assert.equal(shimmedEl.tagName, undefined); |
| 74 | +}); |
| 75 | + |
48 | 76 | test.run(); |
0 commit comments