forked from lodash/lodash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefer.test.js
More file actions
40 lines (32 loc) · 835 Bytes
/
defer.test.js
File metadata and controls
40 lines (32 loc) · 835 Bytes
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
import assert from 'assert';
import { slice } from './utils.js';
import defer from '../defer.js';
describe('defer', function() {
it('should defer `func` execution', function(done) {
var pass = false;
defer(function() { pass = true; });
setTimeout(function() {
assert.ok(pass);
done();
}, 32);
});
it('should provide additional arguments to `func`', function(done) {
var args;
defer(function() {
args = slice.call(arguments);
}, 1, 2);
setTimeout(function() {
assert.deepStrictEqual(args, [1, 2]);
done();
}, 32);
});
it('should be cancelable', function(done) {
var pass = true,
timerId = defer(function() { pass = false; });
clearTimeout(timerId);
setTimeout(function() {
assert.ok(pass);
done();
}, 32);
});
});