forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es.array.flat.js
28 lines (26 loc) · 1013 Bytes
/
es.array.flat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { DESCRIPTORS, STRICT } from '../helpers/constants';
import flat from 'core-js-pure/features/array/flat';
import defineProperty from 'core-js-pure/features/object/define-property';
QUnit.test('Array#flat', assert => {
assert.isFunction(flat);
assert.deepEqual(flat([]), []);
const array = [1, [2, 3], [4, [5, 6]]];
assert.deepEqual(flat(array, 0), array);
assert.deepEqual(flat(array, 1), [1, 2, 3, 4, [5, 6]]);
assert.deepEqual(flat(array), [1, 2, 3, 4, [5, 6]]);
assert.deepEqual(flat(array, 2), [1, 2, 3, 4, 5, 6]);
assert.deepEqual(flat(array, 3), [1, 2, 3, 4, 5, 6]);
assert.deepEqual(flat(array, -1), array);
assert.deepEqual(flat(array, Infinity), [1, 2, 3, 4, 5, 6]);
if (STRICT) {
assert.throws(() => flat(null), TypeError);
assert.throws(() => flat(undefined), TypeError);
}
if (DESCRIPTORS) {
assert.notThrows(() => flat(defineProperty({ length: -1 }, 0, {
get() {
throw new Error();
},
})).length === 0, 'uses ToLength');
}
});