From 9f22e634f5e1586b4236edaaa04dfa08b9f89e83 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 9 Nov 2013 01:06:44 -0800 Subject: [PATCH] Simplify a `_.debounce` and a`_.throttle` test. --- test/test.js | 42 ++++++++++-------------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/test/test.js b/test/test.js index 27bdd0cba..f453852e4 100644 --- a/test/test.js +++ b/test/test.js @@ -1491,17 +1491,14 @@ } }); - asyncTest('should work with `maxWait` option', 4, function() { + test('should work with `maxWait` option', 2, function() { if (!(isRhino && isModularize)) { - var now, - stamp, - limit = 100, + var limit = 256, withCount = 0, withoutCount = 0; var withMaxWait = _.debounce(function() { withCount++; - stamp = +new Date; }, 32, { 'maxWait': 64 }); var withoutMaxWait = _.debounce(function() { @@ -1509,25 +1506,15 @@ }, 32); var start = +new Date; - while (((now = +new Date) - start) < limit || now == stamp) { + while ((new Date - start) < limit) { withMaxWait(); withoutMaxWait(); } ok(withCount > 0); - strictEqual(withoutCount, 0); - - var lastWithCount = withCount, - lastWithoutCount = withoutCount; - - setTimeout(function() { - ok(withCount > lastWithCount); - ok(withoutCount > lastWithoutCount && withoutCount < withCount); - QUnit.start(); - }, 256); + ok(!withoutCount); } else { - skipTest(4); - QUnit.start(); + skipTest(2); } }); @@ -6939,34 +6926,25 @@ }); _.times(2, function(index) { - asyncTest('should trigger trailing call when invoked repeatedly' + (index ? ' and `leading` is `false`' : ''), 2, function() { + test('should trigger a call when invoked repeatedly' + (index ? ' and `leading` is `false`' : ''), 1, function() { if (!(isRhino && isModularize)) { - var now, - stamp, - count = 0, - limit = 100, + var count = 0, + limit = 256, options = index ? { 'leading': false } : {}; var throttled = _.throttle(function() { count++; - stamp = +new Date; }, 32, options); var start = +new Date; - while (((now = +new Date) - start) < limit || now == stamp) { + while ((new Date - start) < limit) { throttled(); } var lastCount = count; ok(count > 1); - - setTimeout(function() { - ok(count > lastCount); - QUnit.start(); - }, 256); } else { - skipTest(2); - QUnit.start(); + skipTest(1); } }); });