p-defer/test.js

15 lines
299 B
JavaScript
Raw Normal View History

2016-10-21 05:07:52 +00:00
import test from 'ava';
2021-04-09 05:21:28 +00:00
import pDefer from './index.js';
2016-10-21 05:07:52 +00:00
const fixture = Symbol('fixture');
2021-04-09 05:21:28 +00:00
function delay(milliseconds) {
const deferred = pDefer();
2021-04-09 05:21:28 +00:00
setTimeout(deferred.resolve, milliseconds, fixture);
2016-10-21 05:07:52 +00:00
return deferred.promise;
}
test('main', async t => {
2016-10-21 05:07:52 +00:00
t.is(await delay(50), fixture);
});