Luke Childs
7 years ago
4 changed files with 30 additions and 59 deletions
@ -1 +0,0 @@ |
|||||
require('browser-env')(['window']); |
|
@ -1,72 +1,49 @@ |
|||||
|
import EventEmitter from 'events'; |
||||
import test from 'ava'; |
import test from 'ava'; |
||||
import jsdom from 'jsdom'; |
import Window from 'window'; |
||||
import whenDomReady from '../'; |
import whenDomReady from '../'; |
||||
|
|
||||
test.cb('callback fires with global document', t => { |
test.cb('callback fires', t => { |
||||
t.plan(1); |
t.plan(1); |
||||
|
const { document } = new Window(); |
||||
whenDomReady(() => { |
whenDomReady(() => { |
||||
t.pass(); |
t.pass(); |
||||
t.end(); |
t.end(); |
||||
}); |
}, document); |
||||
}); |
}); |
||||
|
|
||||
test('Promise resolves with global document', async t => { |
test('Promise resolves', async t => { |
||||
|
const { document } = new Window(); |
||||
t.plan(1); |
t.plan(1); |
||||
await whenDomReady().then(() => t.pass()); |
await whenDomReady(document).then(() => t.pass()); |
||||
}); |
|
||||
|
|
||||
test.cb('callback fires with local document', t => { |
|
||||
t.plan(1); |
|
||||
const config = { |
|
||||
html: '', |
|
||||
onload: window => whenDomReady(() => { |
|
||||
t.pass(); |
|
||||
t.end(); |
|
||||
}, window.document) |
|
||||
}; |
|
||||
jsdom.env(config); |
|
||||
}); |
}); |
||||
|
|
||||
test.cb('Promise resolves with local document', t => { |
test('Promise chain helper passes value through', async t => { |
||||
|
const { document } = new Window(); |
||||
t.plan(1); |
t.plan(1); |
||||
const config = { |
await Promise |
||||
html: '', |
.resolve('foo') |
||||
onload: window => whenDomReady(window.document).then(() => { |
.then(whenDomReady.resume(document)) |
||||
t.pass(); |
.then(val => t.is(val, 'foo')); |
||||
t.end(); |
|
||||
}) |
|
||||
}; |
|
||||
jsdom.env(config); |
|
||||
}); |
}); |
||||
|
|
||||
test.cb('callback fires if we run after DOMContentLoaded', t => { |
test('If document.readyState is already "interactive" run cb', async t => { |
||||
|
const document = { readyState: 'interactive' }; |
||||
t.plan(1); |
t.plan(1); |
||||
const config = { |
await whenDomReady(document).then(() => t.pass()); |
||||
html: '', |
|
||||
created: (err, window) => whenDomReady(() => { |
|
||||
t.pass(); |
|
||||
t.end(); |
|
||||
}, window.document) |
|
||||
}; |
|
||||
jsdom.env(config); |
|
||||
}); |
}); |
||||
|
|
||||
test.cb('Promise resolves if we run after DOMContentLoaded', t => { |
test('If document.readyState is already "complete" run cb', async t => { |
||||
|
const document = { readyState: 'complete' }; |
||||
t.plan(1); |
t.plan(1); |
||||
const config = { |
await whenDomReady(document).then(() => t.pass()); |
||||
html: '', |
|
||||
created: (err, window) => whenDomReady(window.document).then(() => { |
|
||||
t.pass(); |
|
||||
t.end(); |
|
||||
}) |
|
||||
}; |
|
||||
jsdom.env(config); |
|
||||
}); |
}); |
||||
|
|
||||
test('Promise chain helper passes value through', async t => { |
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); |
t.plan(1); |
||||
await Promise |
setTimeout(() => document.emit('DOMContentLoaded'), 500); |
||||
.resolve('foo') |
await whenDomReady(document).then(() => t.pass()); |
||||
.then(whenDomReady.resume()) |
|
||||
.then(val => t.is(val, 'foo')); |
|
||||
}); |
}); |
||||
|
Loading…
Reference in new issue