From f0e32c88ec9f0a6efe299b19f06246216f2370bf Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 7 Aug 2013 09:18:34 -0700 Subject: [PATCH] Add `_.throttle` test. Former-commit-id: f50fe31ee221d1a3c2835b037b58b13c8afdd70f --- test/test.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/test/test.js b/test/test.js index a3fbf67f7..38b906551 100644 --- a/test/test.js +++ b/test/test.js @@ -3429,22 +3429,25 @@ }, 96); }); - asyncTest('should trigger trailing call when invoked repeatedly', function() { - var count = 0, - limit = 96, - throttled = _.throttle(function() { count++; }, 64), - start = new Date; + _.times(2, function(index) { + asyncTest('should trigger trailing call when invoked repeatedly' + (index ? ' and `leading` is `false`' : '') , function() { + var count = 0, + limit = 160, + options = index ? { 'leading': false } : {}, + throttled = _.throttle(function() { count++; }, 64, options), + start = new Date; - while ((new Date - start) < limit) { - throttled(); - } - var lastCount = count; - ok(lastCount > 1); + while ((new Date - start) < limit) { + throttled(); + } + var lastCount = count; + ok(count > 1); - setTimeout(function() { - ok(count > lastCount); - QUnit.start(); - }, 96); + setTimeout(function() { + ok(count > lastCount); + QUnit.start(); + }, 96); + }); }); asyncTest('should apply default options correctly', function() {