-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
79 lines (65 loc) · 1.89 KB
/
test.js
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
import t from 'libtap';
import * as eventBlocker from '@cfware/event-blocker';
const keys = [
'preventDefault',
'stopPropagation',
'stopImmediatePropagation',
'blockEvent',
'immediateBlockEvent'
];
t.same(Object.keys(eventBlocker).sort(), keys.sort());
class EventSnoop {
calls = {
preventDefault: 0,
stopPropagation: 0,
stopImmediatePropagation: 0
};
preventDefault() {
this.calls.preventDefault++;
}
stopPropagation() {
this.calls.stopPropagation++;
}
stopImmediatePropagation() {
this.calls.stopImmediatePropagation++;
}
}
for (const method of ['preventDefault', 'stopPropagation', 'stopImmediatePropagation']) {
const initial = {
preventDefault: 0,
stopPropagation: 0,
stopImmediatePropagation: 0
};
t.test(method, async t => {
t.doesNotThrow(() => eventBlocker[method]());
t.throws(() => eventBlocker[method]({}));
const snoop = new EventSnoop();
t.doesNotThrow(() => eventBlocker[method](snoop));
t.same(snoop.calls, {
...initial,
[method]: 1
});
});
}
t.test('blockEvent', async t => {
t.doesNotThrow(() => eventBlocker.blockEvent());
t.throws(() => eventBlocker.blockEvent({}));
const snoop = new EventSnoop();
t.doesNotThrow(() => eventBlocker.blockEvent(snoop));
t.same(snoop.calls, {
preventDefault: 1,
stopPropagation: 1,
stopImmediatePropagation: 0
});
});
t.test('immediateBlockEvent', async t => {
t.doesNotThrow(() => eventBlocker.immediateBlockEvent());
t.throws(() => eventBlocker.immediateBlockEvent({}));
const snoop = new EventSnoop();
t.doesNotThrow(() => eventBlocker.immediateBlockEvent(snoop));
t.same(snoop.calls, {
preventDefault: 1,
stopPropagation: 1,
stopImmediatePropagation: 1
});
});