1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
import { expect } from 'chai'
import { polyfill } from '../mod.js'
describe('Basic', () => {
before(() => polyfill(globalThis))
it('Globals exist', () => {
const webAPIs = [
'AbortController',
'AbortSignal',
'Blob',
'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('Constructs an Event', () => {
const e = new Event('test')
expect(e.type).to.equal('test')
})
it('Constructs an EventTarget', () => {
const _t = new EventTarget()
})
it('Dispatches an Event on an EventTarget', () => {
const t = new EventTarget()
let pass = false
t.addEventListener('test', (event) => {
pass = true
})
const e = new Event('test')
t.dispatchEvent(e)
expect(pass).to.equal(true)
})
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)
})
it('Relative Indexing Method (String#at)', () => {
expect(String.prototype.at).to.be.a('function')
expect(String.prototype.at.length).to.equal(1)
const example = 'The quick brown fox jumps over the lazy dog.'
expect(example.at(2)).to.equal('e')
expect(example.at(-2)).to.equal('g')
})
it('Relative Indexing Method (Array#at)', () => {
expect(Array.prototype.at).to.be.a('function')
expect(Array.prototype.at.length).to.equal(1)
const example = [1, 3, 5, 7, 9]
expect(example.at(1)).to.equal(3)
expect(example.at(-1)).to.equal(9)
})
it('Relative Indexing Method (TypedArray#at)', () => {
expect(Int8Array.prototype.at).to.be.a('function')
expect(Int8Array.prototype.at.length).to.equal(1)
const example = new Int8Array([1, 3, 5, 7, 9])
expect(example.at(1)).to.equal(3)
expect(example.at(-1)).to.equal(9)
})
it('Object.hasOwn', () => {
expect(Object.hasOwn).to.be.a('function')
expect(Object.hasOwn.length).to.equal(2)
const example = {}
expect(Object.hasOwn(example, 'prop')).to.equal(false)
example.prop = 'exists'
expect(Object.hasOwn(example, 'prop')).to.equal(true)
})
it('Promise.any', () => {
expect(Promise.any).to.be.a('function')
expect(Promise.any.length).to.equal(1)
Promise.any([
Promise.resolve(42),
Promise.reject(-1),
Promise.reject(Infinity),
]).then((result) => {
expect(result).to.equal(42)
})
})
it('String#replaceAll', () => {
expect(String.prototype.replaceAll).to.be.a('function')
expect(String.prototype.replaceAll.length).to.equal(2)
const t1 =
'Of all the sorcerers in Harry Potter, Halo is my favorite sorcerer.'
const t2 = t1.replaceAll('sorcerer', 'philosopher')
const t3 =
'Of all the philosophers in Harry Potter, Halo is my favorite philosopher.'
expect(t2).to.equal(t3)
})
})
|