Skip to content

Commit

Permalink
test: Adjust the test and add one more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdlrahmanSaberAbdo committed Jun 23, 2023
1 parent 0b8f437 commit 79bf40e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/common/test/pipes/parse-enum.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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);
Expand All @@ -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', () => {
Expand Down

0 comments on commit 79bf40e

Please sign in to comment.