From f3c6511593b065f3029e057f2abd42ecc3743303 Mon Sep 17 00:00:00 2001 From: nilshah98 Date: Sun, 26 Nov 2023 15:14:19 +0530 Subject: [PATCH] test: added defaultMap specs --- packages/core/test/unit/utils.test.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/core/test/unit/utils.test.js b/packages/core/test/unit/utils.test.js index 354dc1bb7..f5db2fa06 100644 --- a/packages/core/test/unit/utils.test.js +++ b/packages/core/test/unit/utils.test.js @@ -2,7 +2,8 @@ import { generatePromise, AbortController, yieldTo, - yieldAll + yieldAll, + DefaultMap } from '../../src/utils.js'; describe('Unit / Utils', () => { @@ -165,4 +166,21 @@ describe('Unit / Utils', () => { { done: true, value: [2, 4, null, 3, 6] }); }); }); + + describe('DefaultMap', () => { + it('should throw an error if getDefaultValue is not a function', () => { + expect(() => new DefaultMap('not a function')).toThrow(new Error('getDefaultValue must be a function')); + }); + + it('should return the default value for a key that has not been set', () => { + const map = new DefaultMap((key) => `default value for ${key}`); + expect(map.get('testKey')).toEqual('default value for testKey'); + }); + + it('should return the correct value for a key that has been set', () => { + const map = new DefaultMap((key) => `default value for ${key}`); + map.set('testKey', 'testValue'); + expect(map.get('testKey')).toEqual('testValue'); + }); + }); });