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