|
| 1 | +import * as Interfaces from './../../interfaces'; |
1 | 2 | import { expect } from 'chai'; |
2 | 3 | import { MsvcUtil } from '../../utils/msvc.util'; |
3 | 4 |
|
| 5 | +function equalTest<R>(testPatterns: Interfaces.MsPattern[], expectedResults: R[]) { |
| 6 | + testPatterns.forEach((testPattern: Interfaces.MsPattern, index: number) => { |
| 7 | + const testData = MsvcUtil.transformPatternToRoute(testPattern); |
| 8 | + expect(testData).to.be.equal(expectedResults[index]); |
| 9 | + }); |
| 10 | +} |
| 11 | + |
4 | 12 | describe('MsvcUtil', () => { |
5 | 13 |
|
6 | 14 | describe('transformPatternToRoute', () => { |
| 15 | + describe(`when gets 'number' value`, () => { |
| 16 | + it(`should return the 'number' what is wrapped in a string`, () => { |
| 17 | + const testPatterns = [ |
| 18 | + 1, 150, 12345, |
| 19 | + ]; |
| 20 | + const expectedResults = [ |
| 21 | + `1`, `150`, `12345`, |
| 22 | + ]; |
| 23 | + |
| 24 | + equalTest(testPatterns, expectedResults); |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
7 | 28 | describe(`gets 'string' value`, () => { |
8 | 29 | it(`should return the same string`, () => { |
9 | 30 | const testPattern1 = `pattern1`; |
@@ -101,18 +122,18 @@ describe('MsvcUtil', () => { |
101 | 122 | }); |
102 | 123 | }); |
103 | 124 |
|
104 | | - describe(`gets value with incorrect type (no string/JSON)`, () => { |
| 125 | + describe(`when gets value with incorrect type (no string/number/JSON)`, () => { |
105 | 126 | it(`should throw error`, () => { |
106 | | - const testPattern1 = 150; |
107 | | - const testPattern2 = null; |
108 | | - const testPattern3 = undefined; |
109 | | - const testPattern4 = Symbol(213); |
| 127 | + const testPatterns = [ |
| 128 | + null, |
| 129 | + undefined, |
| 130 | + Symbol(213), |
| 131 | + ]; |
110 | 132 | const errMsg = `The pattern must be of type 'string' or 'object'!`; |
111 | 133 |
|
112 | | - expect(MsvcUtil.transformPatternToRoute.bind(null, testPattern1)).to.throw(errMsg); |
113 | | - expect(MsvcUtil.transformPatternToRoute.bind(null, testPattern2)).to.throw(errMsg); |
114 | | - expect(MsvcUtil.transformPatternToRoute.bind(null, testPattern3)).to.throw(errMsg); |
115 | | - expect(MsvcUtil.transformPatternToRoute.bind(null, testPattern4)).to.throw(errMsg); |
| 134 | + testPatterns.forEach((testPattern: any) => { |
| 135 | + expect(MsvcUtil.transformPatternToRoute.bind(null, testPattern)).to.throw(errMsg); |
| 136 | + }); |
116 | 137 | }); |
117 | 138 | }); |
118 | 139 | }); |
|
0 commit comments