/
functions__throttle.spec.js
65 lines (57 loc) · 1.61 KB
/
functions__throttle.spec.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
modules.define('spec', ['functions__throttle'], function(provide, throttle) {
describe('functions__throttle', function() {
it('should properly throttle given function', function(done) {
var res = [],
throttledFn = throttle(
function(arg) {
res.push(arg);
},
20);
throttledFn(1);
throttledFn(2);
throttledFn(3);
setTimeout(function() {
throttledFn(4);
}, 10);
setTimeout(function() {
throttledFn(5);
res.should.be.eql([1, 4]);
done();
}, 30);
});
it('should properly throttle given function according "invokeAsap" param', function(done) {
var res = [],
throttledFn = throttle(
function(arg) {
res.push(arg);
},
20,
false);
throttledFn(1);
throttledFn(2);
throttledFn(3);
setTimeout(function() {
throttledFn(4);
}, 10);
setTimeout(function() {
throttledFn(5);
setTimeout(function() {
res.should.be.eql([4, 5]);
done();
}, 30);
}, 30);
});
it('should call throttled function with given "ctx" param', function(done) {
var ctx = {},
throttledFn = throttle(
function() {
this.should.be.eql(ctx);
done();
},
20,
ctx);
throttledFn();
});
});
provide();
});