forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes.array.with.js
33 lines (26 loc) · 1.08 KB
/
es.array.with.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
import { STRICT } from '../helpers/constants.js';
QUnit.test('Array#with', assert => {
const { with: withAt } = Array.prototype;
assert.isFunction(withAt);
assert.arity(withAt, 2);
// assert.name(withAt, 'with');
assert.looksNative(withAt);
assert.nonEnumerable(Array.prototype, 'with');
let array = [1, 2, 3, 4, 5];
assert.notSame(array.with(2, 1), array, 'immutable');
assert.deepEqual([1, 2, 3, 4, 5].with(2, 6), [1, 2, 6, 4, 5]);
assert.deepEqual([1, 2, 3, 4, 5].with(-2, 6), [1, 2, 3, 6, 5]);
assert.deepEqual([1, 2, 3, 4, 5].with('1', 6), [1, 6, 3, 4, 5]);
assert.throws(() => [1, 2, 3, 4, 5].with(5, 6), RangeError);
assert.throws(() => [1, 2, 3, 4, 5].with(-6, 6), RangeError);
if (STRICT) {
assert.throws(() => withAt.call(null, 1, 2), TypeError);
assert.throws(() => withAt.call(undefined, 1, 2), TypeError);
}
array = [1, 2];
// eslint-disable-next-line object-shorthand -- constructor
array.constructor = { [Symbol.species]: function () {
return { foo: 1 };
} };
assert.true(array.with(1, 2) instanceof Array, 'non-generic');
});