forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es.array.splice.js
42 lines (41 loc) · 1.41 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
37
38
39
40
41
42
import { STRICT } from '../helpers/constants';
QUnit.test('Array#splice', assert => {
const { splice } = Array.prototype;
assert.isFunction(splice);
assert.arity(splice, 2);
assert.name(splice, 'splice');
assert.looksNative(splice);
assert.nonEnumerable(Array.prototype, 'splice');
let array = [1, 2, 3, 4, 5];
assert.deepEqual(array.splice(2), [3, 4, 5]);
assert.deepEqual(array, [1, 2]);
array = [1, 2, 3, 4, 5];
assert.deepEqual(array.splice(-2), [4, 5]);
assert.deepEqual(array, [1, 2, 3]);
array = [1, 2, 3, 4, 5];
assert.deepEqual(array.splice(2, 2), [3, 4]);
assert.deepEqual(array, [1, 2, 5]);
array = [1, 2, 3, 4, 5];
assert.deepEqual(array.splice(2, -2), []);
assert.deepEqual(array, [1, 2, 3, 4, 5]);
array = [1, 2, 3, 4, 5];
assert.deepEqual(array.splice(2, 2, 6, 7), [3, 4]);
assert.deepEqual(array, [1, 2, 6, 7, 5]);
// ES6 semantics
array = [0, 1, 2];
assert.deepEqual(array.splice(0), [0, 1, 2]);
array = [0, 1, 2];
assert.deepEqual(array.splice(1), [1, 2]);
array = [0, 1, 2];
assert.deepEqual(array.splice(2), [2]);
if (STRICT) {
assert.throws(() => splice.call(null), TypeError);
assert.throws(() => splice.call(undefined), TypeError);
}
array = [];
// eslint-disable-next-line object-shorthand -- constructor
array.constructor = { [Symbol.species]: function () {
return { foo: 1 };
} };
assert.same(array.splice().foo, 1, '@@species');
});