From f5302665f78873df6c19969722814cba90f4704d Mon Sep 17 00:00:00 2001 From: ssube Date: Fri, 4 Oct 2019 08:27:56 -0500 Subject: [PATCH] fix(tests): cover pairs to map helper --- src/interval/MessageInterval.ts | 3 +-- src/utils/Map.ts | 8 +++----- test/error/TestError.ts | 2 ++ test/utils/TestMap.ts | 12 +++++++++++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/interval/MessageInterval.ts b/src/interval/MessageInterval.ts index 1766669e2..31c7dde60 100644 --- a/src/interval/MessageInterval.ts +++ b/src/interval/MessageInterval.ts @@ -27,8 +27,7 @@ export class MessageInterval extends BaseInterval { public async start() { await super.start(); - const transforms: Array> = this.data.transforms; - for (const def of transforms) { + for (const def of this.data.transforms) { const transform = await this.services.createService(def); this.transforms.push(transform); } diff --git a/src/utils/Map.ts b/src/utils/Map.ts index 7d13e3d4a..67a3d4998 100644 --- a/src/utils/Map.ts +++ b/src/utils/Map.ts @@ -124,12 +124,10 @@ export interface NameValuePair { value: TVal; } -export function pairsToMap(pairs: Array> | undefined): Map { +export function pairsToMap(pairs: Array>): Map { const map = new Map(); - if (doesExist(pairs)) { - for (const p of pairs) { - map.set(p.name, p.value); - } + for (const p of pairs) { + map.set(p.name, p.value); } return map; } diff --git a/test/error/TestError.ts b/test/error/TestError.ts index ab2632236..9eee88d9d 100644 --- a/test/error/TestError.ts +++ b/test/error/TestError.ts @@ -5,6 +5,7 @@ import { MimeTypeError } from '../../src/error/MimeTypeError'; import { MissingKeyError } from '../../src/error/MissingKeyError'; import { NotFoundError } from '../../src/error/NotFoundError'; import { NotImplementedError } from '../../src/error/NotImplementedError'; +import { NotInitializedError } from '../../src/error/NotInitializedError'; import { SchemaError } from '../../src/error/SchemaError'; import { SessionRequiredError } from '../../src/error/SessionRequiredError'; import { TimeoutError } from '../../src/error/TimeoutError'; @@ -15,6 +16,7 @@ const errors = [ MissingKeyError, NotFoundError, NotImplementedError, + NotInitializedError, SchemaError, SessionRequiredError, TimeoutError, diff --git a/test/utils/TestMap.ts b/test/utils/TestMap.ts index 673987910..d8d1637df 100644 --- a/test/utils/TestMap.ts +++ b/test/utils/TestMap.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import { NotFoundError } from '../../src/error/NotFoundError'; -import { getHead, getHeadOrDefault, getOrDefault, makeDict, makeMap, mustGet } from '../../src/utils/Map'; +import { getHead, getHeadOrDefault, getOrDefault, makeDict, makeMap, mustGet, pairsToMap } from '../../src/utils/Map'; import { describeLeaks, itLeaks } from '../helpers/async'; const DEFAULT_VALUE = 'default'; @@ -79,4 +79,14 @@ describeLeaks('map utils', async () => { xit('should return the default for nil values'); xit('should return falsy values for existing keys'); }); + + describe('pairs to map helper', () => { + it('should convert pairs', () => { + const result = pairsToMap([{ + name: 'foo', + value: 3, + }]); + expect(result.get('foo')).to.equal(3); + }); + }); });