forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
es.array.slice.js
31 lines (29 loc) · 1.26 KB
/
es.array.slice.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
import { GLOBAL } from '../helpers/constants';
import { slice, isArray } from 'core-js-pure/features/array';
import Symbol from 'core-js-pure/features/symbol';
QUnit.test('Array#slice', assert => {
assert.isFunction(slice);
let array = ['1', '2', '3', '4', '5'];
assert.deepEqual(slice(array), array);
assert.deepEqual(slice(array, 1, 3), ['2', '3']);
assert.deepEqual(slice(array, 1, undefined), ['2', '3', '4', '5']);
assert.deepEqual(slice(array, 1, -1), ['2', '3', '4']);
assert.deepEqual(slice(array, -2, -1), ['4']);
assert.deepEqual(slice(array, -2, -3), []);
const string = '12345';
assert.deepEqual(slice(string), array);
assert.deepEqual(slice(string, 1, 3), ['2', '3']);
assert.deepEqual(slice(string, 1, undefined), ['2', '3', '4', '5']);
assert.deepEqual(slice(string, 1, -1), ['2', '3', '4']);
assert.deepEqual(slice(string, -2, -1), ['4']);
assert.deepEqual(slice(string, -2, -3), []);
const list = GLOBAL.document && document.body && document.body.childNodes;
if (list) {
assert.notThrows(() => isArray(slice(list)), 'works with NodeList');
}
array = [];
array.constructor = { [Symbol.species]: function () { // eslint-disable-line object-shorthand
return { foo: 1 };
} };
assert.same(slice(array).foo, 1, '@@species');
});