-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Loading.test.mjs
51 lines (35 loc) · 1.23 KB
/
Loading.test.mjs
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
// @ts-check
import "./test/polyfillCustomEvent.mjs";
import { deepStrictEqual, strictEqual } from "node:assert";
import { describe, it } from "node:test";
import Loading from "./Loading.mjs";
import assertBundleSize from "./test/assertBundleSize.mjs";
import assertInstanceOf from "./test/assertInstanceOf.mjs";
describe("Class `Loading`.", { concurrency: true }, () => {
it("Bundle size.", async () => {
await assertBundleSize(new URL("./Loading.mjs", import.meta.url), 120);
});
it("Constructor.", () => {
const loading = new Loading();
deepStrictEqual(loading.store, {});
});
it("Events.", () => {
const loading = new Loading();
assertInstanceOf(loading, EventTarget);
/** @type {Event | null} */
let listenedEvent = null;
/** @type {EventListener} */
const listener = (event) => {
listenedEvent = event;
};
const eventName = "a";
const event = new CustomEvent(eventName);
loading.addEventListener(eventName, listener);
loading.dispatchEvent(event);
strictEqual(listenedEvent, event);
listenedEvent = null;
loading.removeEventListener(eventName, listener);
loading.dispatchEvent(new CustomEvent(eventName));
strictEqual(listenedEvent, null);
});
});