mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-15 05:07:49 +00:00
Allow test.'s to support rhino -require with modularized builds.
This commit is contained in:
89
test/test.js
89
test/test.js
@@ -104,6 +104,9 @@
|
||||
/** Detects if running in a PhantomJS web page */
|
||||
var isPhantomPage = typeof callPhantom == 'function';
|
||||
|
||||
/** Detect if running in Rhino */
|
||||
var isRhino = root.java && typeof global == 'function' && global().Array === root.Array;
|
||||
|
||||
/** Use a single "load" function */
|
||||
var load = !amd && typeof require == 'function' ? require : root.load;
|
||||
|
||||
@@ -830,13 +833,19 @@
|
||||
|
||||
(function() {
|
||||
test('subsequent "immediate" debounced calls return the last `func` result', function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var debounced = _.debounce(_.identity, 32, true),
|
||||
result = [debounced('x'), debounced('y')];
|
||||
|
||||
deepEqual(result, ['x', 'x']);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
asyncTest('subsequent debounced calls return the last `func` result', function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var debounced = _.debounce(_.identity, 32);
|
||||
debounced('x');
|
||||
|
||||
@@ -844,9 +853,15 @@
|
||||
equal(debounced('y'), 'x');
|
||||
QUnit.start();
|
||||
}, 64);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
|
||||
asyncTest('should apply default options correctly', function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var count = 0;
|
||||
|
||||
var debounced = _.debounce(function(value) {
|
||||
@@ -860,9 +875,15 @@
|
||||
strictEqual(count, 1);
|
||||
QUnit.start();
|
||||
}, 64);
|
||||
}
|
||||
else {
|
||||
skipTest(2);
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
|
||||
asyncTest('should work with `leading` option', function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var withLeadingAndTrailing,
|
||||
counts = [0, 0, 0];
|
||||
|
||||
@@ -894,9 +915,15 @@
|
||||
|
||||
QUnit.start();
|
||||
}, 64);
|
||||
}
|
||||
else {
|
||||
skipTest(5);
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
|
||||
asyncTest('should work with `trailing` option', function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var withCount = 0,
|
||||
withoutCount = 0;
|
||||
|
||||
@@ -918,9 +945,15 @@
|
||||
strictEqual(withoutCount, 0);
|
||||
QUnit.start();
|
||||
}, 64);
|
||||
}
|
||||
else {
|
||||
skipTest(4);
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
|
||||
asyncTest('should work with `maxWait` option', function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var limit = 100,
|
||||
withCount = 0,
|
||||
withoutCount = 0;
|
||||
@@ -949,6 +982,11 @@
|
||||
ok(withoutCount > lastWithoutCount && withoutCount < withCount);
|
||||
QUnit.start();
|
||||
}, 64);
|
||||
}
|
||||
else {
|
||||
skipTest(4);
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -974,10 +1012,15 @@
|
||||
|
||||
(function() {
|
||||
asyncTest('should accept additional arguments', function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
_.defer(function() {
|
||||
deepEqual(slice.call(arguments), [1, 2, 3]);
|
||||
QUnit.start();
|
||||
}, 1, 2, 3);
|
||||
} else {
|
||||
skipTest();
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -3809,10 +3852,15 @@
|
||||
|
||||
(function() {
|
||||
test('subsequent calls should return the result of the first call', function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var throttled = _.throttle(function(value) { return value; }, 32),
|
||||
result = [throttled('x'), throttled('y')];
|
||||
|
||||
deepEqual(result, ['x', 'x']);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
test('should clear timeout when `func` is called', function() {
|
||||
@@ -3842,6 +3890,7 @@
|
||||
});
|
||||
|
||||
asyncTest('supports recursive calls', function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var count = 0;
|
||||
var throttled = _.throttle(function() {
|
||||
count++;
|
||||
@@ -3857,9 +3906,15 @@
|
||||
ok(count < 3)
|
||||
QUnit.start();
|
||||
}, 32);
|
||||
}
|
||||
else {
|
||||
skipTest(2);
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
|
||||
asyncTest('should not trigger a trailing call when invoked once', function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var count = 0,
|
||||
throttled = _.throttle(function() { count++; }, 32);
|
||||
|
||||
@@ -3870,10 +3925,16 @@
|
||||
equal(count, 1);
|
||||
QUnit.start();
|
||||
}, 96);
|
||||
}
|
||||
else {
|
||||
skipTest(2);
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
|
||||
_.times(2, function(index) {
|
||||
asyncTest('should trigger trailing call when invoked repeatedly' + (index ? ' and `leading` is `false`' : '') , function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var count = 0,
|
||||
limit = 160,
|
||||
options = index ? { 'leading': false } : {},
|
||||
@@ -3890,10 +3951,16 @@
|
||||
ok(count > lastCount);
|
||||
QUnit.start();
|
||||
}, 96);
|
||||
}
|
||||
else {
|
||||
skipTest(2);
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
asyncTest('should apply default options correctly', function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var count = 0;
|
||||
|
||||
var throttled = _.throttle(function(value) {
|
||||
@@ -3909,9 +3976,15 @@
|
||||
strictEqual(count, 2);
|
||||
QUnit.start();
|
||||
}, 64);
|
||||
}
|
||||
else {
|
||||
skipTest(3);
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
|
||||
test('should work with `leading` option', function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
_.forEach([true, { 'leading': true }], function(options) {
|
||||
var withLeading = _.throttle(_.identity, 32, options);
|
||||
equal(withLeading('x'), 'x');
|
||||
@@ -3921,9 +3994,14 @@
|
||||
var withoutLeading = _.throttle(_.identity, 32, options);
|
||||
strictEqual(withoutLeading('x'), undefined);
|
||||
});
|
||||
}
|
||||
else {
|
||||
skipTest(4);
|
||||
}
|
||||
});
|
||||
|
||||
asyncTest('should work with `trailing` option', function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var withCount = 0,
|
||||
withoutCount = 0;
|
||||
|
||||
@@ -3947,9 +4025,15 @@
|
||||
strictEqual(withoutCount, 1);
|
||||
QUnit.start();
|
||||
}, 64);
|
||||
}
|
||||
else {
|
||||
skipTest(6);
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
|
||||
asyncTest('should not update `lastCalled`, at the end of the timeout, when `trailing` is `false`', function() {
|
||||
if (!(isRhino && isModularize)) {
|
||||
var count = 0;
|
||||
|
||||
var throttled = _.throttle(function() {
|
||||
@@ -3963,6 +4047,11 @@
|
||||
equal(count, 2);
|
||||
QUnit.start();
|
||||
}, 128);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
QUnit.start();
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user