From e50bf1fb443fa50bddb89423337f17ba8ea532fd Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 16 May 2016 08:38:20 -0700 Subject: [PATCH] Add `_.throttle` test for a system time of `0`. --- test/test.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/test.js b/test/test.js index f5a64a2ed..1eb3a0941 100644 --- a/test/test.js +++ b/test/test.js @@ -22635,6 +22635,38 @@ done(); }, 192); }); + + QUnit.test('should work with a system time of `0`', function(assert) { + assert.expect(3); + + var done = assert.async(); + + var callCount = 0, + dateCount = 0; + + var lodash = _.runInContext({ + 'Date': { + 'now': function() { + return ++dateCount < 2 ? 0 : +new Date; + } + } + }); + + var throttled = _.throttle(function(value) { + callCount++; + return value; + }, 32); + + var actual = [throttled('a'), throttled('b'), throttled('c')]; + + assert.strictEqual(callCount, 1); + assert.deepEqual(actual, ['a', 'a', 'a']); + + setTimeout(function() { + assert.strictEqual(callCount, 2); + done(); + }, 64); + }); }()); /*--------------------------------------------------------------------------*/