forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes.array.to-spliced.js
34 lines (27 loc) · 1.19 KB
/
es.array.to-spliced.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
33
34
import { STRICT } from '../helpers/constants.js';
QUnit.test('Array#toSpliced', assert => {
const { toSpliced } = Array.prototype;
assert.isFunction(toSpliced);
assert.arity(toSpliced, 2);
assert.name(toSpliced, 'toSpliced');
assert.looksNative(toSpliced);
assert.nonEnumerable(Array.prototype, 'toSpliced');
let array = [1, 2, 3, 4, 5];
assert.notSame(array.toSpliced(2), array, 'immutable');
assert.deepEqual([1, 2, 3, 4, 5].toSpliced(2), [1, 2]);
assert.deepEqual([1, 2, 3, 4, 5].toSpliced(-2), [1, 2, 3]);
assert.deepEqual([1, 2, 3, 4, 5].toSpliced(2, 2), [1, 2, 5]);
assert.deepEqual([1, 2, 3, 4, 5].toSpliced(2, -2), [1, 2, 3, 4, 5]);
assert.deepEqual([1, 2, 3, 4, 5].toSpliced(2, 2, 6, 7), [1, 2, 6, 7, 5]);
if (STRICT) {
assert.throws(() => toSpliced.call(null), TypeError);
assert.throws(() => toSpliced.call(undefined), TypeError);
}
array = [];
// eslint-disable-next-line object-shorthand -- constructor
array.constructor = { [Symbol.species]: function () {
return { foo: 1 };
} };
assert.true(array.toSpliced() instanceof Array, 'non-generic');
assert.true('toSpliced' in Array.prototype[Symbol.unscopables], 'In Array#@@unscopables');
});