forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes.array.concat.js
32 lines (31 loc) · 1.5 KB
/
es.array.concat.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
29
30
31
32
import Symbol from 'core-js-pure/es/symbol';
import concat from 'core-js-pure/es/array/concat';
/* eslint-disable no-sparse-arrays -- required for testing */
QUnit.test('Array#concat', assert => {
assert.isFunction(concat);
let array = [1, 2];
const sparseArray = [1, , 2];
const nonSpreadableArray = [1, 2];
nonSpreadableArray[Symbol.isConcatSpreadable] = false;
const arrayLike = { 0: 1, 1: 2, length: 2 };
const spreadableArrayLike = { 0: 1, 1: 2, length: 2, [Symbol.isConcatSpreadable]: true };
assert.deepEqual(concat(array), [1, 2], '#1');
assert.deepEqual(concat(sparseArray), [1, , 2], '#2');
assert.deepEqual(concat(nonSpreadableArray), [[1, 2]], '#3');
assert.deepEqual(concat(arrayLike), [{ 0: 1, 1: 2, length: 2 }], '#4');
assert.deepEqual(concat(spreadableArrayLike), [1, 2], '#5');
assert.deepEqual(concat([], array), [1, 2], '#6');
assert.deepEqual(concat([], sparseArray), [1, , 2], '#7');
assert.deepEqual(concat([], nonSpreadableArray), [[1, 2]], '#8');
assert.deepEqual(concat([], arrayLike), [{ 0: 1, 1: 2, length: 2 }], '#9');
assert.deepEqual(concat([], spreadableArrayLike), [1, 2], '#10');
assert.deepEqual(concat(array, sparseArray, nonSpreadableArray, arrayLike, spreadableArrayLike), [
1, 2, 1, , 2, [1, 2], { 0: 1, 1: 2, length: 2 }, 1, 2,
], '#11');
array = [];
// eslint-disable-next-line object-shorthand -- constructor
array.constructor = { [Symbol.species]: function () {
return { foo: 1 };
} };
assert.same(concat(array).foo, 1, '@@species');
});