mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 03:47:50 +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() {
|
test('should add two numbers together', 1, function() {
|
||||||
equal(_.add(6, 4), 10);
|
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) {
|
if (!isNpm) {
|
||||||
strictEqual(_(_.constant('x')).attempt(), 'x');
|
strictEqual(_(_.constant('x')).attempt(), 'x');
|
||||||
}
|
}
|
||||||
@@ -1256,6 +1274,15 @@
|
|||||||
skipTest();
|
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);
|
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) {
|
if (!isNpm) {
|
||||||
strictEqual(_('foo bar')[methodName](), converted);
|
strictEqual(_('foo bar')[methodName](), converted);
|
||||||
}
|
}
|
||||||
@@ -1651,6 +1678,15 @@
|
|||||||
skipTest();
|
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');
|
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) {
|
if (!isNpm) {
|
||||||
strictEqual(_('fred').capitalize(), 'Fred');
|
strictEqual(_('fred').capitalize(), 'Fred');
|
||||||
}
|
}
|
||||||
@@ -1698,6 +1734,15 @@
|
|||||||
skipTest();
|
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]);
|
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) {
|
if (!isNpm) {
|
||||||
strictEqual(_(array).first(), 1);
|
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() {
|
test('should work in a lazy chain sequence', 1, function() {
|
||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
var array = [1, 2, 3, 4];
|
var array = [1, 2, 3, 4];
|
||||||
@@ -5308,7 +5362,7 @@
|
|||||||
func = _[methodName],
|
func = _[methodName],
|
||||||
isBaseEach = methodName == '_baseEach';
|
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)) {
|
if (!(isBaseEach || isNpm)) {
|
||||||
var wrapped = _(array)[methodName](_.noop);
|
var wrapped = _(array)[methodName](_.noop);
|
||||||
ok(wrapped instanceof _);
|
ok(wrapped instanceof _);
|
||||||
@@ -5323,7 +5377,7 @@
|
|||||||
var array = [1, 2, 3],
|
var array = [1, 2, 3],
|
||||||
func = _[methodName];
|
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) {
|
if (!isNpm) {
|
||||||
var wrapped = _(array)[methodName](_.noop);
|
var wrapped = _(array)[methodName](_.noop);
|
||||||
ok(!(wrapped instanceof _));
|
ok(!(wrapped instanceof _));
|
||||||
@@ -5332,6 +5386,16 @@
|
|||||||
skipTest();
|
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) {
|
_.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) {
|
if (!isNpm) {
|
||||||
strictEqual(_(collection).includes(3), true);
|
strictEqual(_(collection).includes(3), true);
|
||||||
}
|
}
|
||||||
@@ -6000,6 +6064,15 @@
|
|||||||
skipTest();
|
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({
|
_.each({
|
||||||
@@ -8776,7 +8849,7 @@
|
|||||||
deepEqual(actual, [3, 6, 9]);
|
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) {
|
if (!isNpm) {
|
||||||
strictEqual(_(array).last(), 3);
|
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() {
|
test('should work in a lazy chain sequence', 1, function() {
|
||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
var array = [1, 2, 3, 4];
|
var array = [1, 2, 3, 4];
|
||||||
@@ -11865,13 +11947,18 @@
|
|||||||
strictEqual(_.reduce(object, _.noop), undefined);
|
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) {
|
if (!isNpm) {
|
||||||
var actual = _(array)[methodName](function(sum, num) {
|
strictEqual(_(array)[methodName](add), 6);
|
||||||
return sum + num;
|
}
|
||||||
});
|
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 {
|
else {
|
||||||
skipTest();
|
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() {
|
test('should use a stored reference to `_.sample` when chaining', 2, function() {
|
||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
var sample = _.sample;
|
var sample = _.sample;
|
||||||
@@ -14510,7 +14606,7 @@
|
|||||||
deepEqual(actual, [trimmed, trimmed, trimmed]);
|
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) {
|
if (!isNpm) {
|
||||||
var string = whitespace + 'a b c' + whitespace,
|
var string = whitespace + 'a b c' + whitespace,
|
||||||
expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
|
expected = (index == 2 ? whitespace : '') + 'a b c' + (index == 1 ? whitespace : '');
|
||||||
@@ -14521,6 +14617,16 @@
|
|||||||
skipTest();
|
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() {
|
(function() {
|
||||||
var funcs = [
|
var funcs = [
|
||||||
'add',
|
|
||||||
'clone',
|
'clone',
|
||||||
'contains',
|
'contains',
|
||||||
'every',
|
'every',
|
||||||
|
|||||||
Reference in New Issue
Block a user