2020-03-30 23:09:36 +00:00
|
|
|
import { expect } from 'chai';
|
|
|
|
|
2020-12-29 05:24:46 +00:00
|
|
|
import { defer, deferValue, timeout } from '../../src/Async';
|
2020-03-31 13:29:47 +00:00
|
|
|
import { TimeoutError } from '../../src/error/TimeoutError';
|
2020-03-30 23:09:36 +00:00
|
|
|
|
2020-12-29 05:24:46 +00:00
|
|
|
const TEST_DEFER = 10;
|
|
|
|
const TEST_TOO_LONG = 25;
|
|
|
|
|
2020-06-30 13:14:30 +00:00
|
|
|
describe('async utils', async () => {
|
|
|
|
describe('defer', async () => {
|
2020-12-29 05:24:46 +00:00
|
|
|
it('should resolve', async () => expect(defer(TEST_DEFER)).to.eventually.equal(undefined));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('defer value', async () => {
|
|
|
|
it('should resolve to the given value', async () => expect(deferValue(TEST_DEFER, true)).to.eventually.equal(true));
|
2020-03-30 23:09:36 +00:00
|
|
|
});
|
|
|
|
|
2020-06-30 13:14:30 +00:00
|
|
|
describe('timeout', async () => {
|
2020-12-29 05:24:46 +00:00
|
|
|
it('should reject slow promises', async () => expect(timeout(TEST_DEFER, defer(TEST_TOO_LONG))).to.eventually.be.rejectedWith(TimeoutError));
|
2020-03-30 23:09:36 +00:00
|
|
|
});
|
|
|
|
});
|