Skip to content

Commit

Permalink
test(common): migrate missing tests (#1985)
Browse files Browse the repository at this point in the history
  • Loading branch information
erights authored Jan 27, 2024
1 parent 5b159cb commit 730752e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/common/test/test-from-unique-entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,34 @@ test('test fromUniqueEntries', async t => {
message: 'collision on property name "a": [["a",1],["a",2]]',
},
);

/** @type {[string | symbol, number][]} */
const goodEntries = [
['a', 7],
['b', 8],
[Symbol.hasInstance, 9],
];
const goodObj1 = Object.fromEntries(goodEntries);
t.deepEqual(goodObj1, {
a: 7,
b: 8,
[Symbol.hasInstance]: 9,
});
const goodObj2 = fromUniqueEntries(goodEntries);
t.deepEqual(goodObj2, goodObj1);

/** @type {[string | symbol, number][]} */
const badEntries = [
['a', 7],
['a', 8],
[Symbol.hasInstance, 9],
];
const badObj = Object.fromEntries(badEntries);
t.deepEqual(badObj, {
a: 8,
[Symbol.hasInstance]: 9,
});
t.throws(() => fromUniqueEntries(badEntries), {
message: /^collision on property name "a": .*$/,
});
});
13 changes: 13 additions & 0 deletions packages/common/test/test-object-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,17 @@ test('test objectMap', async t => {
objectMap({ a: 1, b: 2 }, n => n * 2),
{ a: 2, b: 4 },
);

t.deepEqual(
objectMap({ a: 1 }, val => val * 2),
{ a: 2 },
);

t.deepEqual(
objectMap({ a: 1 }, (val, key) => `${key}:${val}`),
{ a: 'a:1' },
);

// @ts-expect-error
t.throws(() => objectMap({ a: 1 }), { message: 'mapFn is not a function' });
});

0 comments on commit 730752e

Please sign in to comment.