mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 00:27:50 +00:00
Add _.propertyDeep and _.propertyDeepOf.
This commit is contained in:
89
test/test.js
89
test/test.js
@@ -11588,6 +11588,58 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.propertyDeep');
|
||||
|
||||
(function() {
|
||||
test('should create a function that plucks a property value of a given object', 3, function() {
|
||||
var object = { 'a': [1, 2], 'b': 3 },
|
||||
prop = _.propertyDeep(['a', 1]);
|
||||
|
||||
strictEqual(prop.length, 1);
|
||||
strictEqual(prop(object), 2);
|
||||
|
||||
prop = _.propertyDeep(['b']);
|
||||
strictEqual(prop(object), 3);
|
||||
});
|
||||
|
||||
test('should work with non-string `prop` arguments', 1, function() {
|
||||
var prop = _.propertyDeep([1]);
|
||||
strictEqual(prop([1, 2, 3]), 2);
|
||||
});
|
||||
|
||||
test('should return a function even for falsey values', 1, function() {
|
||||
var pass = true;
|
||||
|
||||
_.each(falsey, function(keys) {
|
||||
pass = typeof _.propertyDeep(keys) == 'function'
|
||||
});
|
||||
|
||||
ok(pass);
|
||||
});
|
||||
|
||||
test('should pluck inherited property values', 1, function() {
|
||||
function Foo() { this.a = 1; }
|
||||
Foo.prototype.b = 2;
|
||||
|
||||
var prop = _.propertyDeep(['b']);
|
||||
strictEqual(prop(new Foo), 2);
|
||||
});
|
||||
|
||||
test('should work when `object` is nullish', 1, function() {
|
||||
var values = [, null, undefined],
|
||||
expected = _.map(values, _.constant(undefined));
|
||||
|
||||
var actual = _.map(values, function(value, index) {
|
||||
var prop = _.propertyDeep(['a']);
|
||||
return index ? prop(value) : prop();
|
||||
});
|
||||
|
||||
deepEqual(actual, expected);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.propertyOf');
|
||||
|
||||
(function() {
|
||||
@@ -11623,6 +11675,41 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.propertyDeepOf');
|
||||
|
||||
(function() {
|
||||
test('should create a function that plucks a property value of a given key', 3, function() {
|
||||
var object = { 'a': 1, 'b': 2 },
|
||||
propOf = _.propertyDeepOf(object);
|
||||
|
||||
strictEqual(propOf.length, 1);
|
||||
strictEqual(propOf(['a']), 1);
|
||||
strictEqual(propOf(['b']), 2);
|
||||
});
|
||||
|
||||
test('should pluck inherited property values', 1, function() {
|
||||
function Foo() { this.a = 1; }
|
||||
Foo.prototype.b = 2;
|
||||
|
||||
var propOf = _.propertyDeepOf(new Foo);
|
||||
strictEqual(propOf(['b']), 2);
|
||||
});
|
||||
|
||||
test('should work 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 ? _.propertyDeepOf(value) : _.propertyDeepOf();
|
||||
return propOf(['a']);
|
||||
});
|
||||
|
||||
deepEqual(actual, expected);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.pull');
|
||||
|
||||
(function() {
|
||||
@@ -16581,7 +16668,7 @@
|
||||
|
||||
var acceptFalsey = _.difference(allMethods, rejectFalsey);
|
||||
|
||||
test('should accept falsey arguments', 214, function() {
|
||||
test('should accept falsey arguments', 216, function() {
|
||||
var emptyArrays = _.map(falsey, _.constant([])),
|
||||
isExposed = '_' in root,
|
||||
oldDash = root._;
|
||||
|
||||
Reference in New Issue
Block a user