-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
web.set-immediate.js
42 lines (36 loc) · 1.21 KB
/
web.set-immediate.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
import { timeLimitedPromise } from '../helpers/helpers';
import setImmediate from 'core-js-pure/stable/set-immediate';
import clearImmediate from 'core-js-pure/stable/clear-immediate';
QUnit.test('setImmediate / clearImmediate', assert => {
let called = false;
assert.expect(6);
assert.isFunction(setImmediate, 'setImmediate is function');
assert.isFunction(clearImmediate, 'clearImmediate is function');
timeLimitedPromise(1e3, res => {
setImmediate(() => {
called = true;
res();
});
}).then(() => {
assert.required('setImmediate works');
}).catch(() => {
assert.avoid('setImmediate works');
}).then(assert.async());
assert.false(called, 'setImmediate is async');
timeLimitedPromise(1e3, res => {
setImmediate((a, b) => {
res(a + b);
}, 'a', 'b');
}).then(it => {
assert.same(it, 'ab', 'setImmediate works with additional args');
}).catch(() => {
assert.avoid('setImmediate works with additional args');
}).then(assert.async());
timeLimitedPromise(50, res => {
clearImmediate(setImmediate(res));
}).then(() => {
assert.avoid('clearImmediate works');
}).catch(() => {
assert.required('clearImmediate works');
}).then(assert.async());
});