From 730752e67f814aec174627f066aa375a758e1c2a Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Fri, 26 Jan 2024 20:43:20 -0800 Subject: [PATCH] test(common): migrate missing tests (#1985) --- .../common/test/test-from-unique-entries.js | 30 +++++++++++++++++++ packages/common/test/test-object-map.js | 13 ++++++++ 2 files changed, 43 insertions(+) diff --git a/packages/common/test/test-from-unique-entries.js b/packages/common/test/test-from-unique-entries.js index 575a84d64c..5d087e893c 100644 --- a/packages/common/test/test-from-unique-entries.js +++ b/packages/common/test/test-from-unique-entries.js @@ -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": .*$/, + }); }); diff --git a/packages/common/test/test-object-map.js b/packages/common/test/test-object-map.js index 773780d8a8..6500ca5088 100644 --- a/packages/common/test/test-object-map.js +++ b/packages/common/test/test-object-map.js @@ -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' }); });