From 2a92600fa7bb6d928c43aa296565a9efe38fb4cd Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 17 Apr 2013 21:36:37 -0700 Subject: [PATCH] Add `_.throttle` unit test to test `lastCalled`. Former-commit-id: 528ebd3514aacafcde55fad989f955f1fe403811 --- test/test.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index 0e3878b04..ffdaa1836 100644 --- a/test/test.js +++ b/test/test.js @@ -2843,11 +2843,27 @@ }); setTimeout(function() { - strictEqual(withCount, 2); + equal(withCount, 2); strictEqual(withoutCount, 1); QUnit.start(); }, 64); }); + + asyncTest('should not update `lastCalled`, at the end of the timeout, when `trailing` is `false`', function() { + var count = 0; + + var throttled = _.throttle(function() { + count++; + }, 64, { 'trailing': false }); + + _.times(2, throttled); + setTimeout(function() { _.times(2, throttled); }, 100); + + setTimeout(function() { + equal(count, 2); + QUnit.start(); + }, 128); + }); }()); /*--------------------------------------------------------------------------*/