Ensure wait of _.debounce and _.throttle defaults to 0. [closes #991]

This commit is contained in:
jdalton
2015-02-23 08:28:02 -08:00
parent 6840b2cfe5
commit 44006142c7
2 changed files with 25 additions and 3 deletions

View File

@@ -7376,7 +7376,7 @@
* @memberOf _ * @memberOf _
* @category Function * @category Function
* @param {Function} func The function to debounce. * @param {Function} func The function to debounce.
* @param {number} wait The number of milliseconds to delay. * @param {number} [wait=0] The number of milliseconds to delay.
* @param {Object} [options] The options object. * @param {Object} [options] The options object.
* @param {boolean} [options.leading=false] Specify invoking on the leading * @param {boolean} [options.leading=false] Specify invoking on the leading
* edge of the timeout. * edge of the timeout.
@@ -7434,7 +7434,7 @@
if (typeof func != 'function') { if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
wait = wait < 0 ? 0 : wait; wait = wait < 0 ? 0 : (+wait || 0);
if (options === true) { if (options === true) {
var leading = true; var leading = true;
trailing = false; trailing = false;
@@ -7955,7 +7955,7 @@
* @memberOf _ * @memberOf _
* @category Function * @category Function
* @param {Function} func The function to throttle. * @param {Function} func The function to throttle.
* @param {number} wait The number of milliseconds to throttle invocations to. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
* @param {Object} [options] The options object. * @param {Object} [options] The options object.
* @param {boolean} [options.leading=true] Specify invoking on the leading * @param {boolean} [options.leading=true] Specify invoking on the leading
* edge of the timeout. * edge of the timeout.

View File

@@ -13889,6 +13889,28 @@
ok(pass); ok(pass);
}); });
asyncTest('_.' + methodName + ' should have a default `wait` of `0`', 1, function() {
if (!(isRhino && isModularize)) {
var callCount = 0;
var funced = func(function() {
callCount++;
});
funced();
setTimeout(function() {
funced();
strictEqual(callCount, isDebounce ? 1 : 2);
QUnit.start();
}, 32);
}
else {
skipTest();
QUnit.start();
}
});
asyncTest('_.' + methodName + ' should call `func` with the correct `this` binding', 1, function() { asyncTest('_.' + methodName + ' should call `func` with the correct `this` binding', 1, function() {
if (!(isRhino && isModularize)) { if (!(isRhino && isModularize)) {
var object = { var object = {