mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Ensured _.throttle nulls the timeoutId. [closes #129]
Former-commit-id: 24242f513e01adb2827cc3a5af6c8904098a9280
This commit is contained in:
49
test/test.js
49
test/test.js
@@ -1742,24 +1742,12 @@
|
||||
|
||||
(function() {
|
||||
test('subsequent calls should return the result of the first call', function() {
|
||||
var throttled = _.throttle(function(value) { return value; }, 90),
|
||||
var throttled = _.throttle(function(value) { return value; }, 32),
|
||||
result = [throttled('x'), throttled('y')];
|
||||
|
||||
deepEqual(result, ['x', 'x']);
|
||||
});
|
||||
|
||||
test('supports calls in a loop', function() {
|
||||
var counter = 0,
|
||||
throttled = _.throttle(function() { counter++; }, 90),
|
||||
start = new Date,
|
||||
limit = 180;
|
||||
|
||||
while ((new Date - start) < limit) {
|
||||
throttled();
|
||||
}
|
||||
ok(counter > 1);
|
||||
});
|
||||
|
||||
asyncTest('supports recursive calls', function() {
|
||||
var counter = 0;
|
||||
var throttled = _.throttle(function() {
|
||||
@@ -1801,6 +1789,41 @@
|
||||
QUnit.start();
|
||||
}, 260);
|
||||
});
|
||||
|
||||
asyncTest('should not trigger a trailing call when invoked once', function() {
|
||||
var counter = 0,
|
||||
throttled = _.throttle(function() { counter++; }, 32);
|
||||
|
||||
throttled();
|
||||
equal(counter, 1);
|
||||
|
||||
setTimeout(function() {
|
||||
equal(counter, 1);
|
||||
QUnit.start();
|
||||
}, 64);
|
||||
});
|
||||
|
||||
asyncTest('should trigger a trailing call when invoked in a loop', function() {
|
||||
var counter = 0,
|
||||
limit = 90,
|
||||
throttled = _.throttle(function() { counter++; }, 32),
|
||||
start = new Date;
|
||||
|
||||
while ((new Date - start) < limit) {
|
||||
throttled();
|
||||
}
|
||||
setTimeout(function() {
|
||||
throttled();
|
||||
throttled();
|
||||
}, 64);
|
||||
|
||||
setTimeout(function() {
|
||||
ok(counter > 4);
|
||||
QUnit.start();
|
||||
}, 96);
|
||||
|
||||
ok(counter > 1);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user