mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 17:37:50 +00:00
Add maxWait option to _.debounce and implement _.throttle by way of _.debounce. [closes #285]
Former-commit-id: 63b41aac298e5fa89f7922e84b2ed0d5c6545bd3
This commit is contained in:
28
test/test.js
28
test/test.js
@@ -634,6 +634,34 @@
|
||||
QUnit.start();
|
||||
}, 64);
|
||||
});
|
||||
|
||||
asyncTest('should work with `maxWait` option', function() {
|
||||
var limit = 96,
|
||||
withCount = 0,
|
||||
withoutCount = 0;
|
||||
|
||||
var withMaxWait = _.debounce(function() {
|
||||
withCount++;
|
||||
}, 32, { 'maxWait': 64 });
|
||||
|
||||
var withoutMaxWait = _.debounce(function() {
|
||||
withoutCount++;
|
||||
}, 32);
|
||||
|
||||
var start = new Date;
|
||||
while ((new Date - start) < limit) {
|
||||
withMaxWait();
|
||||
withoutMaxWait();
|
||||
}
|
||||
strictEqual(withCount, 1);
|
||||
strictEqual(withoutCount, 0);
|
||||
|
||||
setTimeout(function() {
|
||||
strictEqual(withCount, 2);
|
||||
strictEqual(withoutCount, 1);
|
||||
QUnit.start();
|
||||
}, 64);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user