From 1c47acd040d35d456754b2ca4f774679351bed42 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 11 Feb 2016 00:16:43 -0800 Subject: [PATCH] Ensure `maxWait` isn't processed on a leading invocation if`leading` is `false` and there isn't an max delay queued. [closes #1964] --- lodash.js | 2 +- test/test.js | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index de9196412..673b88fc0 100644 --- a/lodash.js +++ b/lodash.js @@ -8683,7 +8683,7 @@ lastCalled = stamp; } var remaining = maxWait - (stamp - lastCalled), - isCalled = remaining <= 0 || remaining > maxWait; + isCalled = (remaining <= 0 || remaining > maxWait) && (leading || maxTimeoutId); if (isCalled) { if (maxTimeoutId) { diff --git a/test/test.js b/test/test.js index 70fae5921..82f54a48c 100644 --- a/test/test.js +++ b/test/test.js @@ -3945,7 +3945,7 @@ }); QUnit.test('should cancel `maxDelayed` when `delayed` is invoked', function(assert) { - assert.expect(1); + assert.expect(2); var done = assert.async(); @@ -3958,9 +3958,14 @@ debounced(); setTimeout(function() { + debounced(); assert.strictEqual(callCount, 1); - done(); }, 128); + + setTimeout(function() { + assert.strictEqual(callCount, 2); + done(); + }, 192); }); QUnit.test('should invoke the `trailing` call with the correct arguments and `this` binding', function(assert) { @@ -20707,7 +20712,7 @@ }); }); - QUnit.test('should trigger a second throttled call as early as possible when invoked repeatedly', function(assert) { + QUnit.test('should trigger a second throttled call as soon as possible', function(assert) { assert.expect(2); var done = assert.async();