forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es.array.flat-map.js
27 lines (25 loc) · 1005 Bytes
/
es.array.flat-map.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
import { STRICT } from '../helpers/constants';
import flatMap from 'core-js-pure/features/array/flat-map';
QUnit.test('Array#flatMap', assert => {
assert.isFunction(flatMap);
assert.deepEqual(flatMap([], it => it), []);
assert.deepEqual(flatMap([1, 2, 3], it => it), [1, 2, 3]);
assert.deepEqual(flatMap([1, 2, 3], it => [it, it]), [1, 1, 2, 2, 3, 3]);
assert.deepEqual(flatMap([1, 2, 3], it => [[it], [it]]), [[1], [1], [2], [2], [3], [3]]);
assert.deepEqual(flatMap([1, [2, 3]], () => 1), [1, 1]);
const array = [1];
const context = {};
flatMap(array, function (value, index, that) {
assert.same(value, 1);
assert.same(index, 0);
assert.same(that, array);
assert.same(this, context);
}, context);
if (STRICT) {
assert.throws(() => flatMap(null, it => it), TypeError);
assert.throws(() => flatMap(undefined, it => it), TypeError);
}
assert.notThrows(() => flatMap({ length: -1 }, () => {
throw new Error();
}).length === 0, 'uses ToLength');
});