Skip to content

Commit b91374e

Browse files
committed
fix(test): more map helper tests
1 parent 5b15688 commit b91374e

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

test/utils/TestMap.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import { expect } from 'chai';
22

33
import { NotFoundError } from '../../src/error/NotFoundError';
4-
import { getHead, getHeadOrDefault, makeMap, mustGet } from '../../src/utils/Map';
4+
import { getHead, getHeadOrDefault, getOrDefault, makeDict, makeMap, mustGet } from '../../src/utils/Map';
55
import { describeAsync, itAsync } from '../helpers/async';
66

7+
const DEFAULT_VALUE = 'default';
78
const mapKey = 'key';
89
const mapValue = 'value';
910
const singleItem = new Map([[mapKey, mapValue]]);
1011
const multiItem = new Map([[mapKey, [mapValue]]]);
1112

1213
describeAsync('map utils', async () => {
13-
describeAsync('dict to map', async () => {
14+
describeAsync('make dict', async () => {
15+
itAsync('should return an empty dict for nil values', async () => {
16+
/* tslint:disable-next-line:no-null-keyword */
17+
expect(makeDict(null)).to.deep.equal({});
18+
expect(makeDict(undefined)).to.deep.equal({});
19+
});
20+
});
21+
22+
describeAsync('make map', async () => {
1423
itAsync('should convert objects to maps', async () => {
1524
const data = {
1625
bar: '2',
@@ -54,5 +63,20 @@ describeAsync('map utils', async () => {
5463
itAsync('should get the default for missing keys', async () => {
5564
expect(getHeadOrDefault(multiItem, 'nope', mapValue)).to.equal(mapValue);
5665
});
66+
67+
xit('should return the default for nil values');
68+
});
69+
70+
describe('get or default helper', () => {
71+
it('should get the item for existing keys', () => {
72+
expect(getOrDefault(singleItem, mapKey, DEFAULT_VALUE)).to.equal(mapValue);
73+
});
74+
75+
it('should get the item for missing keys', () => {
76+
expect(getOrDefault(singleItem, 'missing', DEFAULT_VALUE)).to.equal(DEFAULT_VALUE);
77+
});
78+
79+
xit('should return the default for nil values');
80+
xit('should return falsy values for existing keys');
5781
});
5882
});

0 commit comments

Comments
 (0)