Ensure _.debounce and _.throttle reset lastCall after cancelling.

This commit is contained in:
Graeme Yeates
2015-06-20 19:42:16 -04:00
committed by jdalton
parent 660bc2eb21
commit 889c184ba3
2 changed files with 24 additions and 0 deletions

View File

@@ -7792,6 +7792,7 @@
if (maxTimeoutId) {
clearTimeout(maxTimeoutId);
}
lastCalled = 0;
maxTimeoutId = timeoutId = trailingCall = undefined;
}

View File

@@ -15889,6 +15889,29 @@
QUnit.start();
}
});
asyncTest('_.' + methodName + ' should reset `lastCalled` after cancelling', 3, function() {
if (!(isRhino && isModularize)) {
var callCount = 0;
var funced = func(function() {
return ++callCount;
}, 32, { 'leading': true });
strictEqual(funced(), 1);
funced.cancel();
strictEqual(funced(), 2);
setTimeout(function() {
strictEqual(callCount, 2);
QUnit.start();
}, 64);
}
else {
skipTest(3);
QUnit.start();
}
});
});
/*--------------------------------------------------------------------------*/