mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
Add callback and thisArg arguments to _.flatten. [closes #204]
Former-commit-id: 166d6af35c3905c87498ee74abd143f6fdba451d
This commit is contained in:
40
test/test.js
40
test/test.js
@@ -789,6 +789,46 @@
|
||||
QUnit.module('lodash.flatten');
|
||||
|
||||
(function() {
|
||||
var array = [{ 'a': [1, [2]] }, { 'a': [3] }];
|
||||
|
||||
test('should work with a `callback`', function() {
|
||||
var actual = _.flatten(array, function(value) {
|
||||
return value.a;
|
||||
});
|
||||
|
||||
deepEqual(actual, [1, 2, 3]);
|
||||
});
|
||||
|
||||
test('should work with `isShallow` and `callback`', function() {
|
||||
var actual = _.flatten(array, true, function(value) {
|
||||
return value.a;
|
||||
});
|
||||
|
||||
deepEqual(actual, [1, [2], 3]);
|
||||
});
|
||||
|
||||
test('should pass the correct `callback` arguments', function() {
|
||||
var args;
|
||||
|
||||
_.flatten(array, function() {
|
||||
args || (args = slice.call(arguments));
|
||||
});
|
||||
|
||||
deepEqual(args, [{ 'a': [1, [2]] }, 0, array]);
|
||||
});
|
||||
|
||||
test('supports the `thisArg` argument', function() {
|
||||
var actual = _.flatten(array, function(value, index) {
|
||||
return this[index].a;
|
||||
}, array);
|
||||
|
||||
deepEqual(actual, [1, 2, 3]);
|
||||
});
|
||||
|
||||
test('should work with a string for `callback`', function() {
|
||||
deepEqual(_.flatten(array, 'a'), [1, 2, 3]);
|
||||
});
|
||||
|
||||
test('should treat sparse arrays as dense', function() {
|
||||
var array = [[1, 2, 3], Array(3)],
|
||||
expected = [1, 2, 3],
|
||||
|
||||
Reference in New Issue
Block a user