mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
Ensure _.debounce with leading and trailing will call the func on the leading edge after a trailing call is performed. [closes #257]
Former-commit-id: 97afe842b2b4c3eb20c9557298e01ec268386ea2
This commit is contained in:
15
test/test.js
15
test/test.js
@@ -558,14 +558,19 @@
|
||||
});
|
||||
|
||||
asyncTest('should work with `leading` option', function() {
|
||||
var counts = [0, 0, 0];
|
||||
var withLeadingAndTrailing,
|
||||
counts = [0, 0, 0];
|
||||
|
||||
_.each([true, { 'leading': true }], function(options, index) {
|
||||
var withLeading = _.debounce(function(value) {
|
||||
var debounced = _.debounce(function(value) {
|
||||
counts[index]++;
|
||||
return value;
|
||||
}, 32, options);
|
||||
|
||||
equal(withLeading('x'), 'x');
|
||||
if (index == 1) {
|
||||
withLeadingAndTrailing = debounced;
|
||||
}
|
||||
equal(debounced('x'), 'x');
|
||||
});
|
||||
|
||||
_.times(2, _.debounce(function() { counts[2]++; }, 32, { 'leading': true }));
|
||||
@@ -578,6 +583,10 @@
|
||||
|
||||
setTimeout(function() {
|
||||
deepEqual(counts, [1, 1, 2]);
|
||||
|
||||
withLeadingAndTrailing('x');
|
||||
equal(counts[1], 2);
|
||||
|
||||
QUnit.start();
|
||||
}, 64);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user