@gjsify/dom-events 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/lib/cjs/index.js +17 -0
- package/lib/esm/index.js +1 -0
- package/package.json +46 -0
- package/src/error-handler.spec.ts +65 -0
- package/src/event-target.spec.ts +470 -0
- package/src/event.spec.ts +492 -0
- package/src/index.ts +1 -0
- package/src/test.mts +8 -0
- package/test.gjs.js +34758 -0
- package/test.gjs.js.map +7 -0
- package/test.gjs.mjs +35720 -0
- package/test.node.js +1226 -0
- package/test.node.js.map +7 -0
- package/test.node.mjs +9879 -0
- package/tsconfig.json +19 -0
- package/tsconfig.types.json +8 -0
- package/tsconfig.types.tsbuildinfo +1 -0
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import { describe, it, expect, assert } from '@gjsify/unit';
|
|
2
|
+
|
|
3
|
+
import { Event, EventTarget } from '@gjsify/dom-events';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// Credits https://github.com/mysticatea/event-target-shim/blob/master/test/event.ts
|
|
7
|
+
|
|
8
|
+
export const EventTest = async () => {
|
|
9
|
+
|
|
10
|
+
await describe("Event.constructor", async () => {
|
|
11
|
+
|
|
12
|
+
await it("should return an Event object", async () => {
|
|
13
|
+
assert(new Event("") instanceof Event)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
await it("should throw a TypeError if called as a function", async () => {
|
|
17
|
+
expect(() => {
|
|
18
|
+
// @ts-expect-error
|
|
19
|
+
Event("") // eslint-disable-line new-cap
|
|
20
|
+
}).toThrow();
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
await describe("Event.type property", async () => {
|
|
25
|
+
|
|
26
|
+
await it("should be the value of the constructor's first argument", async () => {
|
|
27
|
+
const event = new Event("foo")
|
|
28
|
+
expect(event.type).toBe("foo")
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
await describe("Event.target property", async () => {
|
|
34
|
+
await it("should be null", async () => {
|
|
35
|
+
const event = new Event("foo")
|
|
36
|
+
expect(event.target).toBeNull();
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
await it("should be readonly", async () => {
|
|
40
|
+
const event = new Event("foo")
|
|
41
|
+
expect(() => {
|
|
42
|
+
// @ts-expect-error
|
|
43
|
+
event.target = null
|
|
44
|
+
}).toThrow();
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
await describe("Event.currentTarget property", async () => {
|
|
50
|
+
await it("should be null", async () => {
|
|
51
|
+
const event = new Event("foo")
|
|
52
|
+
assert.strictEqual(event.currentTarget, null)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
await it("should be readonly", async () => {
|
|
56
|
+
const event = new Event("foo")
|
|
57
|
+
assert.throws(() => {
|
|
58
|
+
// @ts-expect-error
|
|
59
|
+
event.currentTarget = null
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
await it("should be the event target under dispatching", async () => {
|
|
64
|
+
const target = new EventTarget()
|
|
65
|
+
const event = new Event("foo")
|
|
66
|
+
let ok = false
|
|
67
|
+
|
|
68
|
+
target.addEventListener("foo", () => {
|
|
69
|
+
assert.strictEqual(event.currentTarget, target)
|
|
70
|
+
ok = true
|
|
71
|
+
})
|
|
72
|
+
target.dispatchEvent(event)
|
|
73
|
+
|
|
74
|
+
assert.strictEqual(event.currentTarget, null)
|
|
75
|
+
assert(ok)
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
await describe("Event.composedPath method", async () => {
|
|
80
|
+
await it("should return an empty array", async () => {
|
|
81
|
+
const event = new Event("foo")
|
|
82
|
+
assert.deepStrictEqual(event.composedPath(), [])
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
await it("should return the event target under dispatching", async () => {
|
|
86
|
+
const target = new EventTarget()
|
|
87
|
+
const event = new Event("foo")
|
|
88
|
+
let ok = false
|
|
89
|
+
|
|
90
|
+
target.addEventListener("foo", () => {
|
|
91
|
+
assert.deepStrictEqual(event.composedPath(), [target])
|
|
92
|
+
ok = true
|
|
93
|
+
})
|
|
94
|
+
target.dispatchEvent(event)
|
|
95
|
+
|
|
96
|
+
assert.deepStrictEqual(event.composedPath(), [])
|
|
97
|
+
assert(ok)
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
await describe("Event.NONE property", async () => {
|
|
102
|
+
await it("should be 0", async () => {
|
|
103
|
+
const event = new Event("foo")
|
|
104
|
+
assert.strictEqual(event.NONE, 0)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
await it("should be readonly", async () => {
|
|
108
|
+
const event = new Event("foo")
|
|
109
|
+
assert.throws(() => {
|
|
110
|
+
// @ts-expect-error
|
|
111
|
+
event.NONE = -1
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
await describe("Event.NONE static property", async () => {
|
|
117
|
+
await it("should be 0", async () => {
|
|
118
|
+
assert.strictEqual(Event.NONE, 0)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
await it("should be readonly", async () => {
|
|
122
|
+
assert.throws(() => {
|
|
123
|
+
// @ts-expect-error
|
|
124
|
+
Event.NONE = -1
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
await describe("Event.CAPTURING_PHASE property", async () => {
|
|
130
|
+
await it("should be 1", async () => {
|
|
131
|
+
const event = new Event("foo")
|
|
132
|
+
assert.strictEqual(event.CAPTURING_PHASE, 1)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
await it("should be readonly", async () => {
|
|
136
|
+
const event = new Event("foo")
|
|
137
|
+
assert.throws(() => {
|
|
138
|
+
// @ts-expect-error
|
|
139
|
+
event.CAPTURING_PHASE = -1
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
await describe("Event.CAPTURING_PHASE static property", async () => {
|
|
145
|
+
await it("should be 1", async () => {
|
|
146
|
+
assert.strictEqual(Event.CAPTURING_PHASE, 1)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
await it("should be readonly", async () => {
|
|
150
|
+
assert.throws(() => {
|
|
151
|
+
// @ts-expect-error
|
|
152
|
+
Event.CAPTURING_PHASE = -1
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
await describe("Event.AT_TARGET property", async () => {
|
|
158
|
+
await it("should be 2", async () => {
|
|
159
|
+
const event = new Event("foo")
|
|
160
|
+
assert.strictEqual(event.AT_TARGET, 2)
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
await it("should be readonly", async () => {
|
|
164
|
+
const event = new Event("foo")
|
|
165
|
+
assert.throws(() => {
|
|
166
|
+
// @ts-expect-error
|
|
167
|
+
event.AT_TARGET = -1
|
|
168
|
+
})
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
await describe("Event.AT_TARGET static property", async () => {
|
|
173
|
+
await it("should be 2", async () => {
|
|
174
|
+
assert.strictEqual(Event.AT_TARGET, 2)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
await it("should be readonly", async () => {
|
|
178
|
+
assert.throws(() => {
|
|
179
|
+
// @ts-expect-error
|
|
180
|
+
Event.AT_TARGET = -1
|
|
181
|
+
})
|
|
182
|
+
})
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
await describe("Event.BUBBLING_PHASE property", async () => {
|
|
186
|
+
await it("should be 3", async () => {
|
|
187
|
+
const event = new Event("foo")
|
|
188
|
+
assert.strictEqual(event.BUBBLING_PHASE, 3)
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
await it("should be readonly", async () => {
|
|
192
|
+
const event = new Event("foo")
|
|
193
|
+
assert.throws(() => {
|
|
194
|
+
// @ts-expect-error
|
|
195
|
+
event.BUBBLING_PHASE = -1
|
|
196
|
+
})
|
|
197
|
+
})
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
await describe("Event.BUBBLING_PHASE static property", async () => {
|
|
201
|
+
await it("should be 3", async () => {
|
|
202
|
+
assert.strictEqual(Event.BUBBLING_PHASE, 3)
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
await it("should be readonly", async () => {
|
|
206
|
+
assert.throws(() => {
|
|
207
|
+
// @ts-expect-error
|
|
208
|
+
Event.BUBBLING_PHASE = -1
|
|
209
|
+
})
|
|
210
|
+
})
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
await describe("Event.eventPhase property", async () => {
|
|
214
|
+
await it("should be 0", async () => {
|
|
215
|
+
const event = new Event("foo")
|
|
216
|
+
assert.strictEqual(event.eventPhase, 0)
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
await it("should be readonly", async () => {
|
|
220
|
+
const event = new Event("foo")
|
|
221
|
+
assert.throws(() => {
|
|
222
|
+
// @ts-expect-error
|
|
223
|
+
event.eventPhase = -1
|
|
224
|
+
})
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
await it("should be 2 under dispatching", async () => {
|
|
228
|
+
const target = new EventTarget()
|
|
229
|
+
const event = new Event("foo")
|
|
230
|
+
let ok = false
|
|
231
|
+
|
|
232
|
+
target.addEventListener("foo", () => {
|
|
233
|
+
assert.strictEqual(event.eventPhase, 2)
|
|
234
|
+
ok = true
|
|
235
|
+
})
|
|
236
|
+
target.dispatchEvent(event)
|
|
237
|
+
|
|
238
|
+
assert.strictEqual(event.eventPhase, 0)
|
|
239
|
+
assert(ok)
|
|
240
|
+
})
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
await describe("Event.stopPropagation method", async () => {
|
|
244
|
+
await it("should return undefined", async () => {
|
|
245
|
+
const event = new Event("foo")
|
|
246
|
+
assert.strictEqual(event.stopPropagation(), undefined)
|
|
247
|
+
})
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
await describe("Event.cancelBubble property", async () => {
|
|
251
|
+
|
|
252
|
+
await it("should be false", async () => {
|
|
253
|
+
const event = new Event("foo")
|
|
254
|
+
assert.strictEqual(event.cancelBubble, false)
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
await it("should be true after 'stopPropagation' method was called", async () => {
|
|
258
|
+
const event = new Event("foo")
|
|
259
|
+
event.stopPropagation()
|
|
260
|
+
assert.strictEqual(event.cancelBubble, true)
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
await it("should be true after 'stopImmediatePropagation' method was called", async () => {
|
|
264
|
+
const event = new Event("foo")
|
|
265
|
+
event.stopImmediatePropagation()
|
|
266
|
+
assert.strictEqual(event.cancelBubble, true)
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
await it("should be writable", async () => {
|
|
270
|
+
const event = new Event("foo")
|
|
271
|
+
event.cancelBubble = true
|
|
272
|
+
assert.strictEqual(event.cancelBubble, true)
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
await describe("Event.stopImmediatePropagation method", async () => {
|
|
278
|
+
await it("should return undefined", async () => {
|
|
279
|
+
const event = new Event("foo")
|
|
280
|
+
assert.strictEqual(event.stopImmediatePropagation(), undefined)
|
|
281
|
+
})
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
await describe("'bubbles' property", async () => {
|
|
285
|
+
await it("should be false if the constructor option was not present", async () => {
|
|
286
|
+
const event = new Event("foo")
|
|
287
|
+
assert.strictEqual(event.bubbles, false)
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
await it("should be false if the constructor option was false", async () => {
|
|
291
|
+
const event = new Event("foo", { bubbles: false })
|
|
292
|
+
assert.strictEqual(event.bubbles, false)
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
await it("should be true if the constructor option was true", async () => {
|
|
296
|
+
const event = new Event("foo", { bubbles: true })
|
|
297
|
+
assert.strictEqual(event.bubbles, true)
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
await it("should be readonly", async () => {
|
|
301
|
+
const event = new Event("foo")
|
|
302
|
+
assert.throws(() => {
|
|
303
|
+
// @ts-expect-error
|
|
304
|
+
event.bubbles = true
|
|
305
|
+
})
|
|
306
|
+
})
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
await describe("Event.cancelable property", async () => {
|
|
310
|
+
await it("should be false if the constructor option was not present", async () => {
|
|
311
|
+
const event = new Event("foo")
|
|
312
|
+
assert.strictEqual(event.cancelable, false)
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
await it("should be false if the constructor option was false", async () => {
|
|
316
|
+
const event = new Event("foo", { cancelable: false })
|
|
317
|
+
assert.strictEqual(event.cancelable, false)
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
await it("should be true if the constructor option was true", async () => {
|
|
321
|
+
const event = new Event("foo", { cancelable: true })
|
|
322
|
+
assert.strictEqual(event.cancelable, true)
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
await it("should be readonly", async () => {
|
|
326
|
+
const event = new Event("foo")
|
|
327
|
+
assert.throws(() => {
|
|
328
|
+
// @ts-expect-error
|
|
329
|
+
event.cancelable = true
|
|
330
|
+
})
|
|
331
|
+
})
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
await describe("Event.returnValue property", async () => {
|
|
335
|
+
|
|
336
|
+
await it("should be true", async () => {
|
|
337
|
+
const event = new Event("foo")
|
|
338
|
+
assert.strictEqual(event.returnValue, true)
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
await it("should be true after 'preventDefault' method was called if 'cancelable' is false", async () => {
|
|
342
|
+
const event = new Event("foo")
|
|
343
|
+
event.preventDefault()
|
|
344
|
+
assert.strictEqual(event.returnValue, true)
|
|
345
|
+
// assertWarning(NonCancelableEventWasCanceled)
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
await it("should be false after 'preventDefault' method was called if 'cancelable' is true", async () => {
|
|
349
|
+
const event = new Event("foo", { cancelable: true })
|
|
350
|
+
event.preventDefault()
|
|
351
|
+
assert.strictEqual(event.returnValue, false)
|
|
352
|
+
})
|
|
353
|
+
|
|
354
|
+
await it("should be changed by assignment if 'cancelable' is true", async () => {
|
|
355
|
+
const event = new Event("foo", { cancelable: true })
|
|
356
|
+
event.returnValue = false
|
|
357
|
+
assert.strictEqual(event.returnValue, false)
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
await it("should NOT be changed by the assignment of true after 'preventDefault' method was called", async () => {
|
|
361
|
+
const event = new Event("foo", { cancelable: true })
|
|
362
|
+
event.preventDefault()
|
|
363
|
+
event.returnValue = true
|
|
364
|
+
assert.strictEqual(event.returnValue, false)
|
|
365
|
+
// assertWarning(TruthyWasAssignedToReturnValue)
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
await it("should NOT be changed by the assignment of true after the assginment of false", async () => {
|
|
369
|
+
const event = new Event("foo", { cancelable: true })
|
|
370
|
+
event.returnValue = false
|
|
371
|
+
event.returnValue = true
|
|
372
|
+
assert.strictEqual(event.returnValue, false)
|
|
373
|
+
// assertWarning(TruthyWasAssignedToReturnValue)
|
|
374
|
+
})
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
await describe("Event.preventDefault method", async () => {
|
|
378
|
+
|
|
379
|
+
await it("should return undefined", async () => {
|
|
380
|
+
const event = new Event("foo", { cancelable: true })
|
|
381
|
+
assert.strictEqual(event.preventDefault(), undefined)
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
await it("should return undefined", async () => {
|
|
385
|
+
const event = new Event("foo")
|
|
386
|
+
assert.strictEqual(event.preventDefault(), undefined)
|
|
387
|
+
// assertWarning(NonCancelableEventWasCanceled)
|
|
388
|
+
})
|
|
389
|
+
})
|
|
390
|
+
|
|
391
|
+
await describe("Event.defaultPrevented property", async () => {
|
|
392
|
+
|
|
393
|
+
await it("should be false", async () => {
|
|
394
|
+
const event = new Event("foo")
|
|
395
|
+
assert.strictEqual(event.defaultPrevented, false)
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
await it("should be false after 'preventDefault' method was called if 'cancelable' is false", async () => {
|
|
399
|
+
const event = new Event("foo")
|
|
400
|
+
event.preventDefault()
|
|
401
|
+
assert.strictEqual(event.defaultPrevented, false)
|
|
402
|
+
// assertWarning(NonCancelableEventWasCanceled)
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
await it("should be false after 'preventDefault' method was called if 'cancelable' is true", async () => {
|
|
406
|
+
const event = new Event("foo", { cancelable: true })
|
|
407
|
+
event.preventDefault()
|
|
408
|
+
assert.strictEqual(event.defaultPrevented, true)
|
|
409
|
+
})
|
|
410
|
+
|
|
411
|
+
await it("should be readonly", async () => {
|
|
412
|
+
const event = new Event("foo")
|
|
413
|
+
assert.throws(() => {
|
|
414
|
+
// @ts-expect-error
|
|
415
|
+
event.defaultPrevented = true
|
|
416
|
+
})
|
|
417
|
+
})
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
await describe("Event.composed property", async () => {
|
|
421
|
+
await it("should be false if the constructor option was not present", async () => {
|
|
422
|
+
const event = new Event("foo")
|
|
423
|
+
assert.strictEqual(event.composed, false)
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
await it("should be false if the constructor option was false", async () => {
|
|
427
|
+
const event = new Event("foo", { composed: false })
|
|
428
|
+
assert.strictEqual(event.composed, false)
|
|
429
|
+
})
|
|
430
|
+
|
|
431
|
+
await it("should be true if the constructor option was true", async () => {
|
|
432
|
+
const event = new Event("foo", { composed: true })
|
|
433
|
+
assert.strictEqual(event.composed, true)
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
await it("should be readonly", async () => {
|
|
437
|
+
const event = new Event("foo")
|
|
438
|
+
assert.throws(() => {
|
|
439
|
+
// @ts-expect-error
|
|
440
|
+
event.composed = true
|
|
441
|
+
})
|
|
442
|
+
})
|
|
443
|
+
})
|
|
444
|
+
|
|
445
|
+
await describe("Event.isTrusted property", async () => {
|
|
446
|
+
await it("should be false", async () => {
|
|
447
|
+
const event = new Event("foo")
|
|
448
|
+
assert.strictEqual(event.isTrusted, false)
|
|
449
|
+
})
|
|
450
|
+
|
|
451
|
+
await it("should be readonly", async () => {
|
|
452
|
+
const event = new Event("foo")
|
|
453
|
+
assert.throws(() => {
|
|
454
|
+
// @ts-expect-error
|
|
455
|
+
event.isTrusted = true
|
|
456
|
+
})
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
await it("should NOT be configurable", async () => {
|
|
460
|
+
const event = new Event("foo")
|
|
461
|
+
assert.throws(() => {
|
|
462
|
+
Object.defineProperty(event, "isTrusted", { value: true })
|
|
463
|
+
})
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
await it("should NOT be overridable", async () => {
|
|
467
|
+
class CustomEvent extends Event {
|
|
468
|
+
// @ts-expect-error
|
|
469
|
+
public get isTrusted(): boolean {
|
|
470
|
+
return true
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
const event = new CustomEvent("foo")
|
|
474
|
+
assert.strictEqual(event.isTrusted, false)
|
|
475
|
+
})
|
|
476
|
+
})
|
|
477
|
+
|
|
478
|
+
await describe("Event.timeStamp property", async () => {
|
|
479
|
+
await it("should be a number", async () => {
|
|
480
|
+
const event = new Event("foo")
|
|
481
|
+
assert.strictEqual(typeof event.timeStamp, "number")
|
|
482
|
+
})
|
|
483
|
+
|
|
484
|
+
await it("should be readonly", async () => {
|
|
485
|
+
const event = new Event("foo")
|
|
486
|
+
assert.throws(() => {
|
|
487
|
+
// @ts-expect-error
|
|
488
|
+
event.timeStamp = 0
|
|
489
|
+
})
|
|
490
|
+
})
|
|
491
|
+
})
|
|
492
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@gjsify/deno-runtime/ext/web/02_event'
|
package/src/test.mts
ADDED