-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathunit.js
49 lines (43 loc) · 1.31 KB
/
unit.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
import EventEmitter from 'events';
import test from 'ava';
import Window from 'window';
import whenDomReady from '../';
test.cb('callback fires', t => {
t.plan(1);
const { document } = new Window();
whenDomReady(() => {
t.pass();
t.end();
}, document);
});
test('Promise resolves', async t => {
const { document } = new Window();
t.plan(1);
await whenDomReady(document).then(() => t.pass());
});
test('Promise chain helper passes value through', async t => {
const { document } = new Window();
t.plan(1);
await Promise
.resolve('foo')
.then(whenDomReady.resume(document))
.then(val => t.is(val, 'foo'));
});
test('If document.readyState is already "interactive" run cb', async t => {
const document = { readyState: 'interactive' };
t.plan(1);
await whenDomReady(document).then(() => t.pass());
});
test('If document.readyState is already "complete" run cb', async t => {
const document = { readyState: 'complete' };
t.plan(1);
await whenDomReady(document).then(() => t.pass());
});
test('If document.readyState is "loading" run cb on DOMContentLoaded event', async t => {
const document = new EventEmitter();
document.addEventListener = document.on;
document.readyState = 'loading';
t.plan(1);
setTimeout(() => document.emit('DOMContentLoaded'), 500);
await whenDomReady(document).then(() => t.pass());
});