mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Add tests for _.pluck, _.findWhere, and _.where for their key or source arguments.
This commit is contained in:
29
test/test.js
29
test/test.js
@@ -2681,6 +2681,13 @@
|
|||||||
strictEqual(_.findWhere(objects, { 'a': 1, 'b': 2 }), objects[2]);
|
strictEqual(_.findWhere(objects, { 'a': 1, 'b': 2 }), objects[2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should work with a function for `source`', 1, function() {
|
||||||
|
function source() {}
|
||||||
|
source.a = 2;
|
||||||
|
|
||||||
|
strictEqual(_.findWhere(objects, source), objects[3]);
|
||||||
|
});
|
||||||
|
|
||||||
test('should match all elements when provided an empty `source`', 1, function() {
|
test('should match all elements when provided an empty `source`', 1, function() {
|
||||||
var expected = _.map(empties, _.constant(true));
|
var expected = _.map(empties, _.constant(true));
|
||||||
|
|
||||||
@@ -7005,6 +7012,20 @@
|
|||||||
var objects = [{ 'a': 1 }, null, undefined, { 'a': 4 }];
|
var objects = [{ 'a': 1 }, null, undefined, { 'a': 4 }];
|
||||||
deepEqual(_.pluck(objects, 'a'), [1, undefined, undefined, 4]);
|
deepEqual(_.pluck(objects, 'a'), [1, undefined, undefined, 4]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should coerce `key` to a string', 1, function() {
|
||||||
|
function fn() {}
|
||||||
|
fn.toString = _.constant('fn');
|
||||||
|
|
||||||
|
var objects = [{ 'null': 1 }, { 'undefined': 2 }, { 'fn': 3 }, { '[object Object]': 4 }],
|
||||||
|
values = [null, undefined, fn, {}]
|
||||||
|
|
||||||
|
var actual = _.map(objects, function(object, index) {
|
||||||
|
return _.pluck([object], values[index]);
|
||||||
|
});
|
||||||
|
|
||||||
|
deepEqual(actual, [[1], [2], [3], [4]]);
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
@@ -9583,6 +9604,7 @@
|
|||||||
|
|
||||||
var source = new Foo;
|
var source = new Foo;
|
||||||
source.b = 2;
|
source.b = 2;
|
||||||
|
|
||||||
deepEqual(_.where(objects, source), [{ 'a': 1, 'b': 2 }, { 'a': 2, 'b': 2 }]);
|
deepEqual(_.where(objects, source), [{ 'a': 1, 'b': 2 }, { 'a': 2, 'b': 2 }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -9601,6 +9623,13 @@
|
|||||||
deepEqual(_.where(collection, { 'a': 1 }), [{ 'a': 1 }, { 'a': 1, 'b': 2 }]);
|
deepEqual(_.where(collection, { 'a': 1 }), [{ 'a': 1 }, { 'a': 1, 'b': 2 }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should work with a function for `source`', 1, function() {
|
||||||
|
function source() {}
|
||||||
|
source.a = 2;
|
||||||
|
|
||||||
|
deepEqual(_.where(objects, source), [{ 'a': 2, 'b': 2 }]);
|
||||||
|
});
|
||||||
|
|
||||||
test('should match all elements when provided an empty `source`', 1, function() {
|
test('should match all elements when provided an empty `source`', 1, function() {
|
||||||
var expected = _.map(empties, _.constant(objects));
|
var expected = _.map(empties, _.constant(objects));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user