mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Simplify a _.debounce and a_.throttle test.
This commit is contained in:
42
test/test.js
42
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)) {
|
if (!(isRhino && isModularize)) {
|
||||||
var now,
|
var limit = 256,
|
||||||
stamp,
|
|
||||||
limit = 100,
|
|
||||||
withCount = 0,
|
withCount = 0,
|
||||||
withoutCount = 0;
|
withoutCount = 0;
|
||||||
|
|
||||||
var withMaxWait = _.debounce(function() {
|
var withMaxWait = _.debounce(function() {
|
||||||
withCount++;
|
withCount++;
|
||||||
stamp = +new Date;
|
|
||||||
}, 32, { 'maxWait': 64 });
|
}, 32, { 'maxWait': 64 });
|
||||||
|
|
||||||
var withoutMaxWait = _.debounce(function() {
|
var withoutMaxWait = _.debounce(function() {
|
||||||
@@ -1509,25 +1506,15 @@
|
|||||||
}, 32);
|
}, 32);
|
||||||
|
|
||||||
var start = +new Date;
|
var start = +new Date;
|
||||||
while (((now = +new Date) - start) < limit || now == stamp) {
|
while ((new Date - start) < limit) {
|
||||||
withMaxWait();
|
withMaxWait();
|
||||||
withoutMaxWait();
|
withoutMaxWait();
|
||||||
}
|
}
|
||||||
ok(withCount > 0);
|
ok(withCount > 0);
|
||||||
strictEqual(withoutCount, 0);
|
ok(!withoutCount);
|
||||||
|
|
||||||
var lastWithCount = withCount,
|
|
||||||
lastWithoutCount = withoutCount;
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
ok(withCount > lastWithCount);
|
|
||||||
ok(withoutCount > lastWithoutCount && withoutCount < withCount);
|
|
||||||
QUnit.start();
|
|
||||||
}, 256);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(4);
|
skipTest(2);
|
||||||
QUnit.start();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -6939,34 +6926,25 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
_.times(2, function(index) {
|
_.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)) {
|
if (!(isRhino && isModularize)) {
|
||||||
var now,
|
var count = 0,
|
||||||
stamp,
|
limit = 256,
|
||||||
count = 0,
|
|
||||||
limit = 100,
|
|
||||||
options = index ? { 'leading': false } : {};
|
options = index ? { 'leading': false } : {};
|
||||||
|
|
||||||
var throttled = _.throttle(function() {
|
var throttled = _.throttle(function() {
|
||||||
count++;
|
count++;
|
||||||
stamp = +new Date;
|
|
||||||
}, 32, options);
|
}, 32, options);
|
||||||
|
|
||||||
var start = +new Date;
|
var start = +new Date;
|
||||||
while (((now = +new Date) - start) < limit || now == stamp) {
|
while ((new Date - start) < limit) {
|
||||||
throttled();
|
throttled();
|
||||||
}
|
}
|
||||||
var lastCount = count;
|
var lastCount = count;
|
||||||
ok(count > 1);
|
ok(count > 1);
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
ok(count > lastCount);
|
|
||||||
QUnit.start();
|
|
||||||
}, 256);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(2);
|
skipTest(1);
|
||||||
QUnit.start();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user