Skip to content

Commit

Permalink
test: added defaultMap specs
Browse files Browse the repository at this point in the history
  • Loading branch information
nilshah98 committed Nov 26, 2023
1 parent 98ff139 commit f3c6511
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/core/test/unit/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
generatePromise,
AbortController,
yieldTo,
yieldAll
yieldAll,
DefaultMap
} from '../../src/utils.js';

describe('Unit / Utils', () => {
Expand Down Expand Up @@ -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');
});
});
});

0 comments on commit f3c6511

Please sign in to comment.