forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es.array.splice.js
36 lines (34 loc) · 1.18 KB
/
es.array.splice.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
35
36
import { STRICT } from '../helpers/constants';
import splice from 'core-js-pure/features/array/splice';
import Symbol from 'core-js-pure/features/symbol';
QUnit.test('Array#splice', assert => {
assert.isFunction(splice);
let array = [1, 2, 3, 4, 5];
assert.deepEqual(splice(array, 2), [3, 4, 5]);
assert.deepEqual(array, [1, 2]);
array = [1, 2, 3, 4, 5];
assert.deepEqual(splice(array, -2), [4, 5]);
assert.deepEqual(array, [1, 2, 3]);
array = [1, 2, 3, 4, 5];
assert.deepEqual(splice(array, 2, 2), [3, 4]);
assert.deepEqual(array, [1, 2, 5]);
array = [1, 2, 3, 4, 5];
assert.deepEqual(splice(array, 2, -2), []);
assert.deepEqual(array, [1, 2, 3, 4, 5]);
array = [1, 2, 3, 4, 5];
assert.deepEqual(splice(array, 2, 2, 6, 7), [3, 4]);
assert.deepEqual(array, [1, 2, 6, 7, 5]);
if (STRICT) {
assert.throws(() => splice(null), TypeError);
assert.throws(() => splice(undefined), TypeError);
}
assert.deepEqual(splice({
length: -1,
0: 1,
}), [], 'uses ToLength');
array = [];
array.constructor = { [Symbol.species]: function () { // eslint-disable-line object-shorthand
return { foo: 1 };
} };
assert.same(splice(array).foo, 1, '@@species');
});