Ensure _.throttle clears the timeout when func is called. [closes #86]

Former-commit-id: 6f3b777aa247f059d97f965c02323d4ee6ab8464
This commit is contained in:
John-David Dalton
2012-10-09 02:11:41 -07:00
parent db3b429784
commit fd790566b2
2 changed files with 26 additions and 0 deletions

View File

@@ -1597,6 +1597,31 @@
throttled();
});
asyncTest('should clear timeout when `func` is called', function() {
var now = new Date,
times = [];
var throttled = _.throttle(function() {
times.push(new Date - now);
}, 20);
setTimeout(throttled, 20);
setTimeout(throttled, 20);
setTimeout(throttled, 40);
setTimeout(throttled, 40);
setTimeout(function() {
var actual = _.every(times, function(value, index) {
return index
? (value - times[index - 1]) > 15
: true;
});
ok(actual);
QUnit.start();
}, 120);
});
}());
/*--------------------------------------------------------------------------*/