mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -05:00
f18ee36dc0
* chore: add @astrojs/webapi * chore: update package.json * fix: update file case * fix: remove lowercase file * chore: update tests to use mocha * chore: update LICENSE
87 lines
2.1 KiB
JavaScript
87 lines
2.1 KiB
JavaScript
import { assert, test } from '../run/test.setup.js'
|
|
import { polyfill } from '../mod.js'
|
|
|
|
test(() => {
|
|
return [
|
|
{
|
|
name: 'Includes Custom Element functionality',
|
|
test() {
|
|
const target = {}
|
|
|
|
polyfill(target)
|
|
|
|
assert.equal(Reflect.has(target, 'CustomElementRegistry'), true)
|
|
assert.equal(Reflect.has(target, 'customElements'), true)
|
|
assert.equal(Reflect.has(target, 'HTMLElement'), true)
|
|
},
|
|
},
|
|
{
|
|
name: 'Supports Custom Element creation',
|
|
test() {
|
|
const target = {}
|
|
|
|
polyfill(target)
|
|
|
|
const CustomElement = class HTMLCustomElement extends target.HTMLElement {}
|
|
|
|
target.customElements.define('custom-element', CustomElement)
|
|
|
|
assert.equal(target.customElements.get('custom-element'), CustomElement)
|
|
assert.equal(target.customElements.getName(CustomElement), 'custom-element')
|
|
},
|
|
},
|
|
{
|
|
name: 'Supports Custom Elements created from Document',
|
|
test() {
|
|
const target = {}
|
|
|
|
polyfill(target)
|
|
|
|
assert.equal(target.document.body.localName, 'body')
|
|
assert.equal(target.document.body.tagName, 'BODY')
|
|
|
|
assert.equal(target.document.createElement('custom-element').constructor.name, 'HTMLUnknownElement')
|
|
|
|
const CustomElement = class HTMLCustomElement extends target.HTMLElement {}
|
|
|
|
target.customElements.define('custom-element', CustomElement)
|
|
|
|
assert.equal(target.document.createElement('custom-element').constructor.name, 'HTMLCustomElement')
|
|
},
|
|
},
|
|
{
|
|
name: 'Supports Custom Elements with properties',
|
|
test() {
|
|
const target = {}
|
|
|
|
polyfill(target)
|
|
|
|
const testSymbol = Symbol.for('webapi.test')
|
|
|
|
const CustomElement = class HTMLCustomElement extends target.HTMLElement {
|
|
otherMethod = () => testSymbol
|
|
|
|
method() {
|
|
return this.otherMethod()
|
|
}
|
|
|
|
static method() {
|
|
return this.otherMethod()
|
|
}
|
|
|
|
static otherMethod() {
|
|
return testSymbol
|
|
}
|
|
}
|
|
|
|
target.customElements.define('custom-element', CustomElement)
|
|
|
|
assert.equal(CustomElement.method(), testSymbol)
|
|
|
|
const customElement = new CustomElement()
|
|
|
|
assert.equal(customElement.method(), testSymbol)
|
|
},
|
|
},
|
|
]
|
|
})
|