mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
Add tests for "_.pluck" style callbacks to _.max, _.min, and _.uniq.
This commit is contained in:
44
test/test.js
44
test/test.js
@@ -7250,6 +7250,18 @@
|
||||
strictEqual(actual, isMax ? 1 : 3);
|
||||
});
|
||||
|
||||
test('should work with a "_.pluck" style `callback`', 2, function() {
|
||||
var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }],
|
||||
actual = func(objects, 'a');
|
||||
|
||||
deepEqual(actual, objects[isMax ? 1 : 2]);
|
||||
|
||||
var arrays = [[2], [3], [1]];
|
||||
actual = func(arrays, 0);
|
||||
|
||||
deepEqual(actual, arrays[isMax ? 1 : 2]);
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should work when used as a callback for `_.map`', 1, function() {
|
||||
var array = [[2, 3, 1], [5, 6, 4], [8, 9, 7]],
|
||||
actual = _.map(array, func);
|
||||
@@ -7257,6 +7269,17 @@
|
||||
deepEqual(actual, isMax ? [3, 6, 9] : [1, 4, 7]);
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should work when `callback` returns +/-Infinity', 1, function() {
|
||||
var value = isMax ? -Infinity : Infinity,
|
||||
object = { 'a': value };
|
||||
|
||||
var actual = func([object, { 'a': value }], function(object) {
|
||||
return object.a;
|
||||
});
|
||||
|
||||
strictEqual(actual, object);
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should iterate an object', 1, function() {
|
||||
var actual = func({ 'a': 1, 'b': 2, 'c': 3 });
|
||||
strictEqual(actual, isMax ? 3 : 1);
|
||||
@@ -7269,16 +7292,6 @@
|
||||
});
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should work when `callback` returns +/-Infinity', 1, function() {
|
||||
var object = { 'a': (isMax ? -Infinity : Infinity) };
|
||||
|
||||
var actual = func([object, { 'a': object.a }], function(object) {
|
||||
return object.a;
|
||||
});
|
||||
|
||||
strictEqual(actual, object);
|
||||
});
|
||||
|
||||
test('`_.' + methodName + '` should work with extremely large arrays', 1, function() {
|
||||
var array = _.range(0, 5e5);
|
||||
strictEqual(func(array), isMax ? 499999 : 0);
|
||||
@@ -10758,6 +10771,17 @@
|
||||
deepEqual(actual, [1, 2, 3]);
|
||||
});
|
||||
|
||||
test('should work with a "_.pluck" style `callback`', 2, function() {
|
||||
var actual = _.uniq(objects, 'a');
|
||||
|
||||
deepEqual(actual, objects.slice(0, 3));
|
||||
|
||||
var arrays = [[2], [3], [1], [2], [3], [1]];
|
||||
actual = _.uniq(arrays, 0);
|
||||
|
||||
deepEqual(actual, arrays.slice(0, 3));
|
||||
});
|
||||
|
||||
test('should perform an unsorted uniq operation when used as a callback for `_.map`', 1, function() {
|
||||
var array = [[2, 1, 2], [1, 2, 1]],
|
||||
actual = _.map(array, _.uniq);
|
||||
|
||||
Reference in New Issue
Block a user