astro/packages/webapi/test/basic.js
Erika c55fbcb8ed
Remove more unnecessary polyfills from webapi for Node 16 (#5814)
* feat(webapi): Remove unnecessary polyfills now that we dropped support for Node 14

* feat(webapi): Removed more unnecessary polyfills for Node 16

* chore: changeset
2023-01-10 15:29:06 +01:00

87 lines
2 KiB
JavaScript

import { expect } from 'chai'
import { polyfill } from '../mod.js'
describe('Basic', () => {
before(() => polyfill(globalThis))
it('Globals exist', () => {
const webAPIs = [
'ByteLengthQueuingStrategy',
'CSSStyleSheet',
'CountQueuingStrategy',
'CustomElementRegistry',
'CustomEvent',
'DOMException',
'Document',
'DocumentFragment',
'Element',
'Event',
'EventTarget',
'File',
'FormData',
'HTMLDocument',
'HTMLElement',
'HTMLDivElement',
'HTMLHeadElement',
'HTMLHtmlElement',
'HTMLImageElement',
'HTMLStyleElement',
'HTMLTemplateElement',
'HTMLUnknownElement',
'Headers',
'IntersectionObserver',
'Image',
'MediaQueryList',
'MutationObserver',
'Node',
'ReadableByteStreamController',
'ReadableStream',
'ReadableStreamBYOBReader',
'ReadableStreamBYOBRequest',
'ReadableStreamDefaultController',
'ReadableStreamDefaultReader',
'Request',
'Response',
'ShadowRoot',
'StyleSheet',
'TransformStream',
'WritableStream',
'WritableStreamDefaultController',
'WritableStreamDefaultWriter',
'Window',
'cancelAnimationFrame',
'cancelIdleCallback',
'clearTimeout',
'fetch',
'requestAnimationFrame',
'requestIdleCallback',
'setTimeout',
]
for (const name of webAPIs) {
expect(globalThis[name]).to.be.a('function')
}
})
it('Classes extend as expected', () => {
expect(HTMLElement.prototype).to.be.an.instanceof(Element)
expect(Element.prototype).to.be.an.instanceof(Node)
expect(Node.prototype).to.be.an.instanceof(EventTarget)
})
it('DOM Methods have no effect', () => {
const element = document.createElement('div')
expect(element.innerHTML).to.be.empty
element.innerHTML = 'frozen'
expect(element.innerHTML).to.be.empty
expect(element.textContent).to.be.empty
element.textContent = 'frozen'
expect(element.textContent).to.be.empty
})
it('globalThis.window === globalThis', () => {
expect(globalThis.window).to.equal(globalThis)
})
})