|
/** |
|
* tests js/flattenArray.js |
|
*/ |
|
describe('flattenArray', function () { |
|
var result; |
|
beforeEach(function () { |
|
result = [1, 2, 3, 4, 5, 6, 7]; |
|
}); |
|
|
|
it('handles empty arrays', function () { |
|
var input = []; |
|
expect(flattenArray(input)).toEqual([]); |
|
}); |
|
it('returns empty array when passed non arrays', function () { |
|
var input = 'test'; |
|
expect(flattenArray(input)).toEqual([]); |
|
}); |
|
it('flattens nested arrays of integers', function () { |
|
var input = [1, 2, [3, 4, [5]], 6, 7]; |
|
expect(flattenArray(input)).toEqual(result); |
|
}); |
|
it('ignores unexpected strings', function () { |
|
var input = [1, 2, 'unexpected string', [3, 4, [5]], 6, 7]; |
|
expect(flattenArray(input)).toEqual(result); |
|
}); |
|
it('ignores unexpected null', function () { |
|
var input = [1, 2, null, [3, 4, [5]], 6, 7]; |
|
expect(flattenArray(input)).toEqual(result); |
|
}); |
|
it('ignores unexpected objects', function () { |
|
var input = [1, 2, {}, [3, 4, [5]], 6, 7]; |
|
expect(flattenArray(input)).toEqual(result); |
|
}); |
|
it('correctly parses objects with integers', function () { |
|
var input = [1, 2, {'a': 3, 'b': 4}, 5, 6, 7]; |
|
expect(flattenArray(input)).toEqual(result); |
|
}); |
|
it('correctly parses nested objects with integers', function () { |
|
var input = [1, 2, {'a': 3, 'b': {'c': 4}}, 5, 6, 7]; |
|
expect(flattenArray(input)).toEqual(result); |
|
}); |
|
}); |