mirror of
https://github.com/hanzoai/core-js.git
synced 2026-09-24 16:58:15 +00:00
22 lines
932 B
JavaScript
22 lines
932 B
JavaScript
QUnit.test('Map#getOrInsert', assert => {
|
|
const { getOrInsert } = Map.prototype;
|
|
const { from } = Array;
|
|
assert.isFunction(getOrInsert);
|
|
assert.arity(getOrInsert, 2);
|
|
assert.name(getOrInsert, 'getOrInsert');
|
|
assert.looksNative(getOrInsert);
|
|
assert.nonEnumerable(Map.prototype, 'getOrInsert');
|
|
|
|
let map = new Map([['a', 2]]);
|
|
assert.same(map.getOrInsert('a', 3), 2, 'result#1');
|
|
assert.deepEqual(from(map), [['a', 2]], 'map#1');
|
|
map = new Map([['a', 2]]);
|
|
assert.same(map.getOrInsert('b', 3), 3, 'result#2');
|
|
assert.deepEqual(from(map), [['a', 2], ['b', 3]], 'map#2');
|
|
|
|
assert.throws(() => getOrInsert.call({}, 'a', 1), TypeError, 'non-generic#1');
|
|
assert.throws(() => getOrInsert.call([], 'a', 1), TypeError, 'non-generic#2');
|
|
assert.throws(() => getOrInsert.call(undefined, 'a', 1), TypeError, 'non-generic#3');
|
|
assert.throws(() => getOrInsert.call(null, 'a', 1), TypeError, 'non-generic#4');
|
|
});
|