@gjsify/dom-events 0.3.21 → 0.4.3

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