-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathes.array.map.js
35 lines (34 loc) · 1.37 KB
/
es.array.map.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
import { STRICT } from '../helpers/constants.js';
QUnit.test('Array#map', assert => {
const { map } = Array.prototype;
assert.isFunction(map);
assert.arity(map, 1);
assert.name(map, 'map');
assert.looksNative(map);
assert.nonEnumerable(Array.prototype, 'map');
let array = [1];
const context = {};
array.map(function (value, key, that) {
assert.same(arguments.length, 3, 'correct number of callback arguments');
assert.same(value, 1, 'correct value in callback');
assert.same(key, 0, 'correct index in callback');
assert.same(that, array, 'correct link to array in callback');
assert.same(this, context, 'correct callback context');
}, context);
assert.deepEqual([2, 3, 4], [1, 2, 3].map(value => value + 1));
assert.deepEqual([1, 3, 5], [1, 2, 3].map((value, key) => value + key));
assert.deepEqual([2, 2, 2], [1, 2, 3].map(function () {
return +this;
}, 2));
if (STRICT) {
assert.throws(() => map.call(null, () => { /* empty */ }), TypeError);
assert.throws(() => map.call(undefined, () => { /* empty */ }), TypeError);
}
array = [];
// eslint-disable-next-line object-shorthand -- constructor
array.constructor = { [Symbol.species]: function () {
return { foo: 1 };
} };
// eslint-disable-next-line es/no-nonstandard-array-prototype-properties -- @@species
assert.same(array.map(Boolean).foo, 1, '@@species');
});