mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
Add more chaining tests.
This commit is contained in:
135
test/test.js
135
test/test.js
@@ -962,6 +962,24 @@
|
||||
test('should add two numbers together', 1, function() {
|
||||
equal(_.add(6, 4), 10);
|
||||
});
|
||||
|
||||
test('should return an unwrapped value when implicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
strictEqual(_(1).add(2), 3);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
test('should return a wrapped value when explicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
ok(_(1).chain().add(2) instanceof _);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -1248,7 +1266,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
test('should return an unwrapped value when chaining', 1, function() {
|
||||
test('should return an unwrapped value when implicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
strictEqual(_(_.constant('x')).attempt(), 'x');
|
||||
}
|
||||
@@ -1256,6 +1274,15 @@
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
test('should return a wrapped value when explicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
ok(_(_.constant('x')).chain().attempt() instanceof _);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -1643,7 +1670,7 @@
|
||||
strictEqual(func({ 'toString': _.constant(string) }), converted);
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should return an unwrapped value when chaining', 1, function() {
|
||||
test('`_.' + methodName + '` should return an unwrapped value implicitly when chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
strictEqual(_('foo bar')[methodName](), converted);
|
||||
}
|
||||
@@ -1651,6 +1678,15 @@
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
ok(_('foo bar').chain()[methodName]() instanceof _);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -1690,7 +1726,7 @@
|
||||
strictEqual(_.capitalize(' fred'), ' fred');
|
||||
});
|
||||
|
||||
test('should return an unwrapped value when chaining', 1, function() {
|
||||
test('should return an unwrapped value when implicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
strictEqual(_('fred').capitalize(), 'Fred');
|
||||
}
|
||||
@@ -1698,6 +1734,15 @@
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
test('should return a wrapped value when explicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
ok(_('fred').chain().capitalize() instanceof _);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -4559,7 +4604,7 @@
|
||||
deepEqual(actual, [1, 4, 7]);
|
||||
});
|
||||
|
||||
test('should return an unwrapped value when chaining', 1, function() {
|
||||
test('should return an unwrapped value when implicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
strictEqual(_(array).first(), 1);
|
||||
}
|
||||
@@ -4568,6 +4613,15 @@
|
||||
}
|
||||
});
|
||||
|
||||
test('should return a wrapped value when explicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
ok(_(array).chain().first() instanceof _);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
test('should work in a lazy chain sequence', 1, function() {
|
||||
if (!isNpm) {
|
||||
var array = [1, 2, 3, 4];
|
||||
@@ -5308,7 +5362,7 @@
|
||||
func = _[methodName],
|
||||
isBaseEach = methodName == '_baseEach';
|
||||
|
||||
test('`_.' + methodName + '` should return a wrapped value when chaining', 1, function() {
|
||||
test('`_.' + methodName + '` should return a wrapped value when implicitly chaining', 1, function() {
|
||||
if (!(isBaseEach || isNpm)) {
|
||||
var wrapped = _(array)[methodName](_.noop);
|
||||
ok(wrapped instanceof _);
|
||||
@@ -5323,7 +5377,7 @@
|
||||
var array = [1, 2, 3],
|
||||
func = _[methodName];
|
||||
|
||||
test('`_.' + methodName + '` should return an unwrapped value when chaining', 1, function() {
|
||||
test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
var wrapped = _(array)[methodName](_.noop);
|
||||
ok(!(wrapped instanceof _));
|
||||
@@ -5332,6 +5386,16 @@
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should return a wrapped value when implicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
var wrapped = _(array).chain()[methodName](_.noop);
|
||||
ok(wrapped instanceof _);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
_.each(_.difference(methods, arrayMethods, forInMethods), function(methodName) {
|
||||
@@ -5992,7 +6056,7 @@
|
||||
});
|
||||
});
|
||||
|
||||
test('should work with ' + key + ' and return an unwrapped value when chaining', 1, function() {
|
||||
test('should work with ' + key + ' and return an unwrapped value implicitly when chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
strictEqual(_(collection).includes(3), true);
|
||||
}
|
||||
@@ -6000,6 +6064,15 @@
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
test('should work with ' + key + ' and return a wrapped value when explicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
ok(_(collection).chain().includes(3) instanceof _);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
_.each({
|
||||
@@ -8776,7 +8849,7 @@
|
||||
deepEqual(actual, [3, 6, 9]);
|
||||
});
|
||||
|
||||
test('should return an unwrapped value when chaining', 1, function() {
|
||||
test('should return an unwrapped value when implicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
strictEqual(_(array).last(), 3);
|
||||
}
|
||||
@@ -8785,6 +8858,15 @@
|
||||
}
|
||||
});
|
||||
|
||||
test('should return a wrapped value when explicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
ok(_(array).chain().last() instanceof _);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
test('should work in a lazy chain sequence', 1, function() {
|
||||
if (!isNpm) {
|
||||
var array = [1, 2, 3, 4];
|
||||
@@ -11865,13 +11947,18 @@
|
||||
strictEqual(_.reduce(object, _.noop), undefined);
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should return an unwrapped value when chaining', 1, function() {
|
||||
test('`_.' + methodName + '` should return an unwrapped value when implicityly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
var actual = _(array)[methodName](function(sum, num) {
|
||||
return sum + num;
|
||||
});
|
||||
strictEqual(_(array)[methodName](add), 6);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
strictEqual(actual, 6);
|
||||
test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
ok(_(array).chain()[methodName](add) instanceof _);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
@@ -12343,6 +12430,15 @@
|
||||
}
|
||||
});
|
||||
|
||||
test('should return a wrapped value when explicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
ok(_(array).chain().sample() instanceof _);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
test('should use a stored reference to `_.sample` when chaining', 2, function() {
|
||||
if (!isNpm) {
|
||||
var sample = _.sample;
|
||||
@@ -14510,7 +14606,7 @@
|
||||
deepEqual(actual, [trimmed, trimmed, trimmed]);
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should return an unwrapped value when chaining', 1, function() {
|
||||
test('`_.' + methodName + '` should return an unwrapped value when implicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
var string = whitespace + 'a b c' + whitespace,
|
||||
expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
|
||||
@@ -14521,6 +14617,16 @@
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should return a wrapped value when explicitly chaining', 1, function() {
|
||||
if (!isNpm) {
|
||||
var string = whitespace + 'a b c' + whitespace;
|
||||
ok(_(string).chain()[methodName]() instanceof _);
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -15609,7 +15715,6 @@
|
||||
|
||||
(function() {
|
||||
var funcs = [
|
||||
'add',
|
||||
'clone',
|
||||
'contains',
|
||||
'every',
|
||||
|
||||
Reference in New Issue
Block a user