mirror of
https://github.com/hanzoai/core-js.git
synced 2026-09-24 16:58:15 +00:00
29 lines
1.2 KiB
JavaScript
29 lines
1.2 KiB
JavaScript
QUnit.test('Map#findKey', assert => {
|
|
const { findKey } = Map.prototype;
|
|
|
|
assert.isFunction(findKey);
|
|
assert.arity(findKey, 1);
|
|
assert.name(findKey, 'findKey');
|
|
assert.looksNative(findKey);
|
|
assert.nonEnumerable(Map.prototype, 'findKey');
|
|
|
|
const map = new Map([[1, 2]]);
|
|
const context = {};
|
|
map.findKey(function (value, key, that) {
|
|
assert.same(arguments.length, 3, 'correct number of callback arguments');
|
|
assert.same(value, 2, 'correct value in callback');
|
|
assert.same(key, 1, 'correct key in callback');
|
|
assert.same(that, map, 'correct link to map in callback');
|
|
assert.same(this, context, 'correct callback context');
|
|
}, context);
|
|
|
|
assert.same(new Map([[1, 2], [2, 3], [3, 4]]).findKey(it => it % 2), 2);
|
|
assert.same(new Map().findKey(it => it === 42), undefined);
|
|
|
|
assert.throws(() => findKey.call(new Set(), () => { /* empty */ }), TypeError);
|
|
assert.throws(() => findKey.call({}, () => { /* empty */ }), TypeError);
|
|
assert.throws(() => findKey.call([], () => { /* empty */ }), TypeError);
|
|
assert.throws(() => findKey.call(undefined, () => { /* empty */ }), TypeError);
|
|
assert.throws(() => findKey.call(null, () => { /* empty */ }), TypeError);
|
|
});
|