mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 08:57:49 +00:00
Ensure _.debounce performs a trailing call, when both leading and trailing are true, only after the throttled function is called more than once. [closes #243]
Former-commit-id: 59ac6bc4ece373623f2bd753b662b8cc974cabc8
This commit is contained in:
19
test/test.js
19
test/test.js
@@ -552,16 +552,29 @@
|
||||
}, 64);
|
||||
});
|
||||
|
||||
test('should work with `leading` option', function() {
|
||||
_.each([true, { 'leading': true }], function(options) {
|
||||
var withLeading = _.debounce(_.identity, 32, options);
|
||||
asyncTest('should work with `leading` option', function() {
|
||||
var counts = [0, 0, 0];
|
||||
_.each([true, { 'leading': true }], function(options, index) {
|
||||
var withLeading = _.debounce(function(value) {
|
||||
counts[index]++;
|
||||
return value;
|
||||
}, 32, options);
|
||||
|
||||
equal(withLeading('x'), 'x');
|
||||
});
|
||||
|
||||
_.times(2, _.debounce(function() { counts[2]++; }, 32, { 'leading': true }));
|
||||
strictEqual(counts[2], 1);
|
||||
|
||||
_.each([false, { 'leading': false }], function(options) {
|
||||
var withoutLeading = _.debounce(_.identity, 32, options);
|
||||
strictEqual(withoutLeading('x'), undefined);
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
deepEqual(counts, [1, 1, 2]);
|
||||
QUnit.start();
|
||||
}, 64);
|
||||
});
|
||||
|
||||
asyncTest('should work with `trailing` option', function() {
|
||||
|
||||
Reference in New Issue
Block a user