forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes.array.to-reversed.js
62 lines (51 loc) · 1.38 KB
/
es.array.to-reversed.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { STRICT } from '../helpers/constants';
QUnit.test('Array#toReversed', assert => {
const { toReversed } = Array.prototype;
assert.isFunction(toReversed);
assert.arity(toReversed, 0);
assert.name(toReversed, 'toReversed');
assert.looksNative(toReversed);
assert.nonEnumerable(Array.prototype, 'toReversed');
let array = [1, 2];
assert.notSame(array.toReversed(), array, 'immutable');
assert.deepEqual([1, 2.2, 3.3].toReversed(), [3.3, 2.2, 1], 'basic');
const object = {};
array = {
0: undefined,
1: 2,
2: 1,
3: 'X',
4: -1,
5: 'a',
6: true,
7: object,
8: NaN,
10: Infinity,
length: 11,
};
const expected = [
Infinity,
undefined,
NaN,
object,
true,
'a',
-1,
'X',
1,
2,
undefined,
];
assert.deepEqual(toReversed.call(array), expected, 'non-array target');
array = [1];
// eslint-disable-next-line object-shorthand -- constructor
array.constructor = { [Symbol.species]: function () {
return { foo: 1 };
} };
assert.true(array.toReversed() instanceof Array, 'non-generic');
if (STRICT) {
assert.throws(() => toReversed.call(null, () => { /* empty */ }, 1), TypeError);
assert.throws(() => toReversed.call(undefined, () => { /* empty */ }, 1), TypeError);
}
assert.true('toReversed' in Array.prototype[Symbol.unscopables], 'In Array#@@unscopables');
});