mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 07:17:50 +00:00
Simplify deep property tests.
This commit is contained in:
142
test/test.js
142
test/test.js
@@ -6943,14 +6943,14 @@
|
||||
QUnit.test('should not support deep paths', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var actual = _.fromPairs([['a.b.c', 1]]);
|
||||
assert.deepEqual(actual, { 'a.b.c': 1 });
|
||||
var actual = _.fromPairs([['a.b', 1]]);
|
||||
assert.deepEqual(actual, { 'a.b': 1 });
|
||||
});
|
||||
|
||||
QUnit.test('should support consuming the return value of `_.toPairs`', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var object = { 'a.b.c': 1 };
|
||||
var object = { 'a.b': 1 };
|
||||
assert.deepEqual(_.fromPairs(_.toPairs(object)), object);
|
||||
});
|
||||
|
||||
@@ -7159,13 +7159,13 @@
|
||||
QUnit.test('`_.' + methodName + '` should support deep paths', function(assert) {
|
||||
assert.expect(4);
|
||||
|
||||
var object = { 'a': { 'b': { 'c': 3 } } };
|
||||
var object = { 'a': { 'b': 2 } };
|
||||
|
||||
lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
assert.strictEqual(func(object, path), true);
|
||||
});
|
||||
|
||||
lodashStable.each(['a.c.b', ['a', 'c', 'b']], function(path) {
|
||||
lodashStable.each(['a.a', ['a', 'a']], function(path) {
|
||||
assert.strictEqual(func(object, path), false);
|
||||
});
|
||||
});
|
||||
@@ -7242,9 +7242,9 @@
|
||||
QUnit.test('`_.' + methodName + '` should check for a key over a path', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } };
|
||||
var object = { 'a.b': 1 };
|
||||
|
||||
lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
|
||||
lodashStable.each(['a.b', ['a.b']], function(path) {
|
||||
assert.strictEqual(func(object, path), true);
|
||||
});
|
||||
});
|
||||
@@ -7335,7 +7335,7 @@
|
||||
var values = [, null, undefined],
|
||||
expected = lodashStable.map(values, alwaysFalse);
|
||||
|
||||
lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
var actual = lodashStable.map(values, function(value, index) {
|
||||
var object = index ? { 'a': value } : {};
|
||||
return func(object, path);
|
||||
@@ -8095,7 +8095,7 @@
|
||||
|
||||
var actual = lodashStable.map(values, function(value) {
|
||||
try {
|
||||
return _.invoke(value, 'a.b.c', 1, 2);
|
||||
return _.invoke(value, 'a.b', 1, 2);
|
||||
} catch (e) {}
|
||||
});
|
||||
|
||||
@@ -11756,8 +11756,8 @@
|
||||
QUnit.test('should support deep paths for `_.matchesProperty` shorthands', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var object = { 'a': { 'b': { 'c': { 'd': 1, 'e': 2 } } } },
|
||||
matches = _.iteratee(['a.b.c', { 'e': 2 }]);
|
||||
var object = { 'a': { 'b': { 'c': 1, 'd': 2 } } },
|
||||
matches = _.iteratee(['a.b', { 'c': 1 }]);
|
||||
|
||||
assert.strictEqual(matches(object), true);
|
||||
});
|
||||
@@ -11806,10 +11806,10 @@
|
||||
QUnit.test('should support deep paths for `_.property` shorthands', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var object = { 'a': { 'b': { 'c': 3 } } },
|
||||
prop = _.iteratee('a.b.c');
|
||||
var object = { 'a': { 'b': 2 } },
|
||||
prop = _.iteratee('a.b');
|
||||
|
||||
assert.strictEqual(prop(object), 3);
|
||||
assert.strictEqual(prop(object), 2);
|
||||
});
|
||||
|
||||
QUnit.test('should work with functions created by `_.partial` and `_.partialRight`', function(assert) {
|
||||
@@ -13694,10 +13694,10 @@
|
||||
QUnit.test('should support deep paths', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a': { 'b': { 'c': 3 } } };
|
||||
var object = { 'a': { 'b': 2 } };
|
||||
|
||||
lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
||||
var matches = _.matchesProperty(path, 3);
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
var matches = _.matchesProperty(path, 2);
|
||||
assert.strictEqual(matches(object), true);
|
||||
});
|
||||
});
|
||||
@@ -13729,10 +13729,10 @@
|
||||
QUnit.test('should match a key over a path', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } };
|
||||
var object = { 'a.b': 1, 'a': { 'b': 2 } };
|
||||
|
||||
lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
|
||||
var matches = _.matchesProperty(path, 3);
|
||||
lodashStable.each(['a.b', ['a.b']], function(path) {
|
||||
var matches = _.matchesProperty(path, 1);
|
||||
assert.strictEqual(matches(object), true);
|
||||
});
|
||||
});
|
||||
@@ -14859,11 +14859,11 @@
|
||||
QUnit.test('should work with deep property values', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a': { 'b': { 'c': alwaysThree } } };
|
||||
var object = { 'a': { 'b': alwaysTwo } };
|
||||
|
||||
lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
var method = _.method(path);
|
||||
assert.strictEqual(method(object), 3);
|
||||
assert.strictEqual(method(object), 2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14914,11 +14914,11 @@
|
||||
QUnit.test('should use a key over a path', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a.b.c': alwaysThree, 'a': { 'b': { 'c': alwaysFour } } };
|
||||
var object = { 'a.b': alwaysOne, 'a': { 'b': alwaysTwo } };
|
||||
|
||||
lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
|
||||
lodashStable.each(['a.b', ['a.b']], function(path) {
|
||||
var method = _.method(path);
|
||||
assert.strictEqual(method(object), 3);
|
||||
assert.strictEqual(method(object), 1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15014,11 +15014,11 @@
|
||||
QUnit.test('should work with deep property values', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a': { 'b': { 'c': alwaysThree } } };
|
||||
var object = { 'a': { 'b': alwaysTwo } };
|
||||
|
||||
lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
var methodOf = _.methodOf(object);
|
||||
assert.strictEqual(methodOf(path), 3);
|
||||
assert.strictEqual(methodOf(path), 2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15069,11 +15069,11 @@
|
||||
QUnit.test('should use a key over a path', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a.b.c': alwaysThree, 'a': { 'b': { 'c': alwaysFour } } };
|
||||
var object = { 'a.b': alwaysOne, 'a': { 'b': alwaysTwo } };
|
||||
|
||||
lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
|
||||
lodashStable.each(['a.b', ['a.b']], function(path) {
|
||||
var methodOf = _.methodOf(object);
|
||||
assert.strictEqual(methodOf(path), 3);
|
||||
assert.strictEqual(methodOf(path), 1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17144,11 +17144,11 @@
|
||||
QUnit.test('should pluck deep property values', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a': { 'b': { 'c': 3 } } };
|
||||
var object = { 'a': { 'b': 2 } };
|
||||
|
||||
lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
var prop = _.property(path);
|
||||
assert.strictEqual(prop(object), 3);
|
||||
assert.strictEqual(prop(object), 2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17199,11 +17199,11 @@
|
||||
QUnit.test('should pluck a key over a path', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } };
|
||||
var object = { 'a.b': 1, 'a': { 'b': 2 } };
|
||||
|
||||
lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
|
||||
lodashStable.each(['a.b', ['a.b']], function(path) {
|
||||
var prop = _.property(path);
|
||||
assert.strictEqual(prop(object), 3);
|
||||
assert.strictEqual(prop(object), 1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17273,11 +17273,11 @@
|
||||
QUnit.test('should pluck deep property values', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a': { 'b': { 'c': 3 } } },
|
||||
var object = { 'a': { 'b': 2 } },
|
||||
propOf = _.propertyOf(object);
|
||||
|
||||
lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
||||
assert.strictEqual(propOf(path), 3);
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
assert.strictEqual(propOf(path), 2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17331,11 +17331,11 @@
|
||||
QUnit.test('should pluck a key over a path', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } },
|
||||
var object = { 'a.b': 1, 'a': { 'b': 2 } },
|
||||
propOf = _.propertyOf(object);
|
||||
|
||||
lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
|
||||
assert.strictEqual(propOf(path), 3);
|
||||
lodashStable.each(['a.b', ['a.b']], function(path) {
|
||||
assert.strictEqual(propOf(path), 1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17583,15 +17583,15 @@
|
||||
assert.expect(3);
|
||||
|
||||
var array = [];
|
||||
array.a = { 'b': { 'c': 3 } };
|
||||
array.a = { 'b': 2 };
|
||||
|
||||
var actual = _.pullAt(array, 'a.b.c');
|
||||
var actual = _.pullAt(array, 'a.b');
|
||||
|
||||
assert.deepEqual(actual, [3]);
|
||||
assert.deepEqual(array.a, { 'b': {} });
|
||||
assert.deepEqual(actual, [2]);
|
||||
assert.deepEqual(array.a, {});
|
||||
|
||||
try {
|
||||
actual = _.pullAt(array, 'a.b.c.d.e');
|
||||
actual = _.pullAt(array, 'a.b.c');
|
||||
} catch (e) {}
|
||||
|
||||
assert.deepEqual(actual, [undefined]);
|
||||
@@ -18517,20 +18517,20 @@
|
||||
QUnit.test('`_.' + methodName + '` should get deep property values', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a': { 'b': { 'c': 3 } } };
|
||||
var object = { 'a': { 'b': 2 } };
|
||||
|
||||
lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
||||
assert.strictEqual(func(object, path), 3);
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
assert.strictEqual(func(object, path), 2);
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should get a key over a path', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a.b.c': 3, 'a': { 'b': { 'c': 4 } } };
|
||||
var object = { 'a.b': 1, 'a': { 'b': 2 } };
|
||||
|
||||
lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
|
||||
assert.strictEqual(func(object, path), 3);
|
||||
lodashStable.each(['a.b', ['a.b']], function(path) {
|
||||
assert.strictEqual(func(object, path), 1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18620,11 +18620,11 @@
|
||||
QUnit.test('`_.' + methodName + '` should follow `path` over non-plain objects', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var paths = ['a.b.c', ['a', 'b', 'c']];
|
||||
var paths = ['a.b', ['a', 'b']];
|
||||
|
||||
lodashStable.each(paths, function(path) {
|
||||
numberProto.a = { 'b': { 'c': 1 } };
|
||||
assert.strictEqual(func(0, path), 1);
|
||||
numberProto.a = { 'b': 2 };
|
||||
assert.strictEqual(func(0, path), 2);
|
||||
delete numberProto.a;
|
||||
});
|
||||
});
|
||||
@@ -18640,7 +18640,7 @@
|
||||
});
|
||||
|
||||
var actual = lodashStable.transform(values, function(result, value) {
|
||||
lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
result.push(
|
||||
func(object, path, value),
|
||||
func(null, path, value)
|
||||
@@ -19161,30 +19161,30 @@
|
||||
QUnit.test('`_.' + methodName + '` should set deep property values', function(assert) {
|
||||
assert.expect(4);
|
||||
|
||||
var object = { 'a': { 'b': { 'c': oldValue } } };
|
||||
var object = { 'a': { 'b': oldValue } };
|
||||
|
||||
lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
var actual = func(object, path, updater);
|
||||
|
||||
assert.strictEqual(actual, object);
|
||||
assert.strictEqual(object.a.b.c, value);
|
||||
assert.strictEqual(object.a.b, value);
|
||||
|
||||
object.a.b.c = oldValue;
|
||||
object.a.b = oldValue;
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should set a key over a path', function(assert) {
|
||||
assert.expect(4);
|
||||
|
||||
var object = { 'a.b.c': oldValue };
|
||||
var object = { 'a.b': oldValue };
|
||||
|
||||
lodashStable.each(['a.b.c', ['a.b.c']], function(path) {
|
||||
lodashStable.each(['a.b', ['a.b']], function(path) {
|
||||
var actual = func(object, path, updater);
|
||||
|
||||
assert.strictEqual(actual, object);
|
||||
assert.deepEqual(object, { 'a.b.c': value });
|
||||
assert.deepEqual(object, { 'a.b': value });
|
||||
|
||||
object['a.b.c'] = oldValue;
|
||||
object['a.b'] = oldValue;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23811,10 +23811,10 @@
|
||||
QUnit.test('should unset deep property values', function(assert) {
|
||||
assert.expect(4);
|
||||
|
||||
lodashStable.each(['a.b.c', ['a', 'b', 'c']], function(path) {
|
||||
var object = { 'a': { 'b': { 'c': null } } };
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
var object = { 'a': { 'b': null } };
|
||||
assert.strictEqual(_.unset(object, path), true);
|
||||
assert.deepEqual(object, { 'a': { 'b': {} } });
|
||||
assert.deepEqual(object, { 'a': {} });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user