You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

33 lines
967 B

import test from 'ava';
import Window from 'window';
import whenDomReady from '../';
test('whenDomReady is a function', t => {
t.is(typeof whenDomReady, 'function');
});
test('whenDomReady returns a Promise', t => {
const { document } = new Window();
t.true(whenDomReady(document) instanceof Promise);
});
test('whenDomReady.resume is a function', t => {
t.is(typeof whenDomReady.resume, 'function');
});
test('whenDomReady.resume returns a function that returns a promise', t => {
const { document } = new Window();
const returnValue = whenDomReady.resume(document);
t.is(typeof returnValue, 'function');
t.true(returnValue() instanceof Promise);
});
test('Promise value always resolves to undefined', async t => {
t.plan(2);
const { document } = new Window();
const promises = [
whenDomReady(() => 'foo', document).then(val => t.is(val, undefined)),
whenDomReady(document).then(val => t.is(val, undefined))
];
await Promise.all(promises);
});