-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
es.array.flat.js
28 lines (26 loc) · 1004 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.js';
import flat from 'core-js-pure/es/array/flat';
import defineProperty from 'core-js-pure/es/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');
}
});