Add tests for _.map, _.invoke, _.shuffle, and _.sortBy for treating numbers as empty.

This commit is contained in:
John-David Dalton
2014-03-24 09:14:28 -07:00
parent ce01d696a0
commit 76f668dddd

View File

@@ -3732,6 +3732,10 @@
deepEqual(_.invoke(object, 'toFixed', 1), ['1.0', '2.0', '3.0']);
});
test('should treat number values for `collection` as empty', 1, function() {
deepEqual(_.invoke(1), []);
});
test('should work with `null` or `undefined` elements', 1, function() {
var array = ['a', null, undefined, 'd'];
deepEqual(_.invoke(array, 'toUpperCase'), ['A', undefined, undefined, 'D']);
@@ -5374,7 +5378,7 @@
}
});
test('should accept a falsey `array` argument', 1, function() {
test('should accept a falsey `collection` argument', 1, function() {
var expected = _.map(falsey, _.constant([]));
var actual = _.map(falsey, function(value, index) {
@@ -5386,6 +5390,10 @@
deepEqual(actual, expected);
});
test('should treat number values for `collection` as empty', 1, function() {
deepEqual(_.map(1), []);
});
test('should be aliased', 1, function() {
strictEqual(_.collect, _.map);
});
@@ -7410,6 +7418,10 @@
deepEqual(actual.sort(), array);
});
test('should treat number values for `collection` as empty', 1, function() {
deepEqual(_.shuffle(1), []);
});
_.forEach({
'literal': 'abc',
'object': Object('abc')
@@ -7670,6 +7682,10 @@
deepEqual(actual, [3, 1, 2]);
});
test('should treat number values for `collection` as empty', 1, function() {
deepEqual(_.sortBy(1), []);
});
test('should support sorting by an array of properties', 1, function() {
var actual = _.sortBy(objects, ['a', 'b']);
deepEqual(actual, [objects[2], objects[0], objects[3], objects[1]]);