Add _.throttle test.

Former-commit-id: f50fe31ee221d1a3c2835b037b58b13c8afdd70f
This commit is contained in:
John-David Dalton
2013-08-07 09:18:34 -07:00
parent 5ae3eccaf1
commit f0e32c88ec

View File

@@ -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() {