-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest.js
52 lines (37 loc) · 1.08 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
import test from 'ava';
import delay from 'delay';
import doNotDisturb from './index.js';
let isEnabledInitially;
test.before(async () => {
isEnabledInitially = await doNotDisturb.isEnabled();
});
test.after(async () => {
await doNotDisturb.toggle(isEnabledInitially);
});
test('main', async t => {
const isEnabled = await doNotDisturb.isEnabled();
await doNotDisturb.toggle();
t.not(isEnabled, await doNotDisturb.isEnabled());
await doNotDisturb.disable();
t.false(await doNotDisturb.isEnabled());
await doNotDisturb.toggle(false);
t.false(await doNotDisturb.isEnabled());
await doNotDisturb.enable();
t.true(await doNotDisturb.isEnabled());
const beforeToggle = await doNotDisturb.isEnabled();
const listener = async value => {
t.not(value, beforeToggle);
t.is(value, await doNotDisturb.isEnabled());
};
doNotDisturb.on('change', listener, {
pollInterval: 50,
});
await doNotDisturb.toggle();
await delay(100);
doNotDisturb.off('change', listener);
doNotDisturb.on('change', value => {
t.true(value);
});
await doNotDisturb.toggle();
await delay(100);
});