Add _.property and _.propertyOf tests for deep paths.

This commit is contained in:
jdalton
2015-04-03 12:05:00 -05:00
parent 88e59c9a5a
commit adc687f0a0

View File

@@ -11637,6 +11637,23 @@
strictEqual(prop(new Foo), 2);
});
test('should pluck deep property values', 2, function() {
var object = { 'a': { 'b': { 'c': 3 } } },
prop = _.property('a.b.c');
strictEqual(prop(object), 3);
prop = _.property(['a', 'b', 'c']);
strictEqual(prop(object), 3);
});
test('should pluck a key before treating it as a path', 1, function() {
var object = { 'a.b.c': 3 },
prop = _.property('a.b.c');
strictEqual(prop(object), 3);
});
test('should work when `object` is nullish', 1, function() {
var values = [, null, undefined],
expected = _.map(values, _.constant(undefined));
@@ -11648,6 +11665,18 @@
deepEqual(actual, expected);
});
test('should work with deep paths when `object` is nullish', 1, function() {
var values = [, null, undefined],
expected = _.map(values, _.constant(undefined));
var actual = _.map(values, function(value, index) {
var prop = _.property('a.b.c');
return index ? prop(value) : prop();
});
deepEqual(actual, expected);
});
}());
/*--------------------------------------------------------------------------*/
@@ -11672,6 +11701,21 @@
strictEqual(propOf('b'), 2);
});
test('should pluck deep property values', 2, function() {
var object = { 'a': { 'b': { 'c': 3 } } },
propOf = _.propertyOf(object);
strictEqual(propOf('a.b.c'), 3);
strictEqual(propOf(['a', 'b', 'c']), 3);
});
test('should pluck a key before treating it as a path', 1, function() {
var object = { 'a.b.c': 3 },
propOf = _.propertyOf(object);
strictEqual(propOf('a.b.c'), 3);
});
test('should work when `object` is nullish', 1, function() {
var values = [, null, undefined],
expected = _.map(values, _.constant(undefined));
@@ -11683,6 +11727,18 @@
deepEqual(actual, expected);
});
test('should work with deep paths when `object` is nullish', 1, function() {
var values = [, null, undefined],
expected = _.map(values, _.constant(undefined));
var actual = _.map(values, function(value, index) {
var propOf = index ? _.propertyOf(value) : _.propertyOf();
return propOf('a.b.c');
});
deepEqual(actual, expected);
});
}());
/*--------------------------------------------------------------------------*/