Improve accuracy of _.throttle.

This commit is contained in:
Corbacho
2016-02-06 22:19:11 +00:00
committed by John-David Dalton
parent 6752d75ad0
commit e392b8e240
2 changed files with 25 additions and 1 deletions

View File

@@ -20635,6 +20635,30 @@
});
});
QUnit.test('should trigger a second throttled call as early as possible when invoked repeatedly', function(assert) {
assert.expect(2);
var done = assert.async();
var callCount = 0;
var throttled = _.throttle(function() {
callCount++;
}, 128, { 'leading': false });
throttled();
setTimeout(function() {
assert.strictEqual(callCount, 1);
throttled();
}, 192);
setTimeout(function() {
assert.strictEqual(callCount, 2);
done();
}, 288);
});
QUnit.test('should apply default options', function(assert) {
assert.expect(3);