From 79bf40e53983cbde01f428f725eb9a58787bbc87 Mon Sep 17 00:00:00 2001 From: AbdlrahmanSaberAbdo Date: Fri, 23 Jun 2023 18:38:24 +0300 Subject: [PATCH] test: Adjust the test and add one more test cases --- .../common/test/pipes/parse-enum.pipe.spec.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/common/test/pipes/parse-enum.pipe.spec.ts b/packages/common/test/pipes/parse-enum.pipe.spec.ts index d3ca5192038..ac49f4caf51 100644 --- a/packages/common/test/pipes/parse-enum.pipe.spec.ts +++ b/packages/common/test/pipes/parse-enum.pipe.spec.ts @@ -14,10 +14,17 @@ describe('ParseEnumPipe', () => { Up = 'UP', } let target: ParseEnumPipe; + let tatargetWithOptionIsTrue: ParseEnumPipe; + beforeEach(() => { target = new ParseEnumPipe(Direction, { exceptionFactory: (error: any) => new CustomTestError(), }); + + tatargetWithOptionIsTrue = new ParseEnumPipe(Direction, { + exceptionFactory: (error: any) => new CustomTestError(), + optional: true, + }); }); describe('transform', () => { describe('when validation passes', () => { @@ -27,7 +34,7 @@ describe('ParseEnumPipe', () => { ); }); - it('should not throw an error if enumType is undefined/null and isOptional is true', async () => { + it('should not throw an error if enumType is undefined/null and optional is true', async () => { const target = new ParseEnumPipe('DOWN', { optional: true }); const value = await target.transform(undefined, {} as ArgumentMetadata); expect(value).to.equal(undefined); @@ -39,6 +46,12 @@ describe('ParseEnumPipe', () => { target.transform('DOWN', {} as ArgumentMetadata), ).to.be.rejectedWith(CustomTestError); }); + + it('should throw an error if enumType is wrong even optional is true', async () => { + return expect( + tatargetWithOptionIsTrue.transform('DOWN', {} as ArgumentMetadata), + ).to.be.rejectedWith(CustomTestError); + }); }); }); describe('constructor', () => {