mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Add debounce/throttle test for calling cancel and flush without anything queued.
This commit is contained in:
@@ -9137,10 +9137,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function trailingEdge(time) {
|
function trailingEdge(time) {
|
||||||
if (timerId !== undefined) {
|
clearTimeout(timerId);
|
||||||
clearTimeout(timerId);
|
timerId = undefined;
|
||||||
timerId = undefined;
|
|
||||||
}
|
|
||||||
// Only invoke if we have `lastArgs` which means `func` has been
|
// Only invoke if we have `lastArgs` which means `func` has been
|
||||||
// debounced at least once.
|
// debounced at least once.
|
||||||
if (trailing && lastArgs) {
|
if (trailing && lastArgs) {
|
||||||
|
|||||||
23
test/test.js
23
test/test.js
@@ -21782,14 +21782,33 @@
|
|||||||
}, 32, { 'leading': false });
|
}, 32, { 'leading': false });
|
||||||
|
|
||||||
funced();
|
funced();
|
||||||
var actual = funced.flush();
|
assert.strictEqual(funced.flush(), 1);
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
assert.strictEqual(actual, 1);
|
|
||||||
assert.strictEqual(callCount, 1);
|
assert.strictEqual(callCount, 1);
|
||||||
done();
|
done();
|
||||||
}, 64);
|
}, 64);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('_.' + methodName + ' should noop `cancel` and `flush` when nothing is queued', function(assert) {
|
||||||
|
assert.expect(2);
|
||||||
|
|
||||||
|
var done = assert.async();
|
||||||
|
|
||||||
|
var callCount = 0;
|
||||||
|
|
||||||
|
var funced = func(function() {
|
||||||
|
callCount++;
|
||||||
|
}, 32);
|
||||||
|
|
||||||
|
funced.cancel();
|
||||||
|
assert.strictEqual(funced.flush(), undefined);
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
assert.strictEqual(callCount, 0);
|
||||||
|
done();
|
||||||
|
}, 64);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user