|
1 | 1 | import { expect } from 'chai';
|
2 | 2 |
|
3 | 3 | 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'; |
5 | 5 | import { describeAsync, itAsync } from '../helpers/async';
|
6 | 6 |
|
| 7 | +const DEFAULT_VALUE = 'default'; |
7 | 8 | const mapKey = 'key';
|
8 | 9 | const mapValue = 'value';
|
9 | 10 | const singleItem = new Map([[mapKey, mapValue]]);
|
10 | 11 | const multiItem = new Map([[mapKey, [mapValue]]]);
|
11 | 12 |
|
12 | 13 | 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 () => { |
14 | 23 | itAsync('should convert objects to maps', async () => {
|
15 | 24 | const data = {
|
16 | 25 | bar: '2',
|
@@ -54,5 +63,20 @@ describeAsync('map utils', async () => {
|
54 | 63 | itAsync('should get the default for missing keys', async () => {
|
55 | 64 | expect(getHeadOrDefault(multiItem, 'nope', mapValue)).to.equal(mapValue);
|
56 | 65 | });
|
| 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'); |
57 | 81 | });
|
58 | 82 | });
|
0 commit comments