mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Add _.throttle test.
Former-commit-id: f50fe31ee221d1a3c2835b037b58b13c8afdd70f
This commit is contained in:
31
test/test.js
31
test/test.js
@@ -3429,22 +3429,25 @@
|
|||||||
}, 96);
|
}, 96);
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('should trigger trailing call when invoked repeatedly', function() {
|
_.times(2, function(index) {
|
||||||
var count = 0,
|
asyncTest('should trigger trailing call when invoked repeatedly' + (index ? ' and `leading` is `false`' : '') , function() {
|
||||||
limit = 96,
|
var count = 0,
|
||||||
throttled = _.throttle(function() { count++; }, 64),
|
limit = 160,
|
||||||
start = new Date;
|
options = index ? { 'leading': false } : {},
|
||||||
|
throttled = _.throttle(function() { count++; }, 64, options),
|
||||||
|
start = new Date;
|
||||||
|
|
||||||
while ((new Date - start) < limit) {
|
while ((new Date - start) < limit) {
|
||||||
throttled();
|
throttled();
|
||||||
}
|
}
|
||||||
var lastCount = count;
|
var lastCount = count;
|
||||||
ok(lastCount > 1);
|
ok(count > 1);
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
ok(count > lastCount);
|
ok(count > lastCount);
|
||||||
QUnit.start();
|
QUnit.start();
|
||||||
}, 96);
|
}, 96);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('should apply default options correctly', function() {
|
asyncTest('should apply default options correctly', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user