Skip to content

Commit

Permalink
chore(tests): add await to rejects style error tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMaz committed Dec 7, 2023
1 parent 7c1f996 commit f28ce25
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/nestjs-auth-jwt/src/auth-jwt.strategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe(AuthJwtStrategy, () => {
const t = async () => {
await authJwtStrategy.validate(authorizationPayload);
};
expect(t).rejects.toThrow(UnauthorizedException);
await expect(t).rejects.toThrow(UnauthorizedException);
});
});
});
6 changes: 3 additions & 3 deletions packages/nestjs-auth-local/src/auth-local.strategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ describe(AuthLocalStrategy, () => {

it('should throw error on validateOrReject', async () => {
const t = () => authLocalStrategy.validate(USERNAME, '');
expect(t).rejects.toThrow();
await expect(t).rejects.toThrow();
});

it('should return no user on userLookupService.byUsername', async () => {
jest.spyOn(userLookUpService, 'byUsername').mockResolvedValue(null);

const t = () => authLocalStrategy.validate(USERNAME, PASSWORD);
expect(t).rejects.toThrow(UnauthorizedException);
await expect(t).rejects.toThrow(UnauthorizedException);
});

it('should be invalid on passwordService.validateObject', async () => {
Expand All @@ -78,7 +78,7 @@ describe(AuthLocalStrategy, () => {
.mockResolvedValue(false);

const t = () => authLocalStrategy.validate(USERNAME, PASSWORD);
expect(t).rejects.toThrow(UnauthorizedException);
await expect(t).rejects.toThrow(UnauthorizedException);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe(AuthRefreshStrategy, () => {

const t = () =>
authRefreshStrategy.validate(authorizationPayloadInterface);
expect(t).rejects.toThrow(UnauthorizedException);
await expect(t).rejects.toThrow(UnauthorizedException);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe(VerifyTokenService, () => {
const t = async () => {
await verifyTokenService.accessToken(token);
};
expect(t).rejects.toThrow(BadRequestException);
await expect(t).rejects.toThrow(BadRequestException);
});
});

Expand All @@ -57,7 +57,7 @@ describe(VerifyTokenService, () => {
const t = async () => {
await verifyTokenService.refreshToken(token);
};
expect(t).rejects.toThrow(BadRequestException);
await expect(t).rejects.toThrow(BadRequestException);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe(EventDispatchService, () => {

eventEmitter.on(testEvent.key, listener);

expect(eventDispatchService.async(testEvent)).rejects.toThrowError(
await expect(eventDispatchService.async(testEvent)).rejects.toThrowError(
EventDispatchException,
);
});
Expand Down
10 changes: 5 additions & 5 deletions packages/nestjs-jwt/src/jwt.strategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe(JwtStrategy, () => {
it('should throw exception', async () => {
jest.spyOn(jwtStrategyOptions, 'jwtFromRequest').mockReturnValue('');
const t = async () => await jwtStrategy.authenticate(req);
expect(t).rejects.toThrow();
await expect(t).rejects.toThrow();
});

it('should throw exception', async () => {
Expand All @@ -39,7 +39,7 @@ describe(JwtStrategy, () => {
throw new Error();
});
const t = async () => await jwtStrategy.authenticate(req);
expect(t).rejects.toThrow();
await expect(t).rejects.toThrow();
});

it('should throw exception', async () => {
Expand All @@ -49,17 +49,17 @@ describe(JwtStrategy, () => {
throw new NotAnErrorException(new Error());
});
const t = async () => await jwtStrategy.authenticate(req);
expect(t).rejects.toThrow();
await expect(t).rejects.toThrow();
});

it('should throw exception', async () => {
const t = async () => jwtStrategy['verifyTokenCallback']();
expect(t).rejects.toThrow();
await expect(t).rejects.toThrow();
});

it('should throw exception', async () => {
const t = async () => jwtStrategy['verifyTokenCallback'](new Error());
expect(t).rejects.toThrow();
await expect(t).rejects.toThrow();
});

// it('should throw exception', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/nestjs-jwt/src/services/jwt-issue.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe(JwtIssueService, () => {
throw new Error();
});
const t = async () => await jwtIssueService.accessToken(token);
expect(t).rejects.toThrowError();
await expect(t).rejects.toThrowError();
});
});

Expand All @@ -43,7 +43,7 @@ describe(JwtIssueService, () => {
throw new Error();
});
const t = async () => await jwtIssueService.refreshToken(token);
expect(t).rejects.toThrowError();
await expect(t).rejects.toThrowError();
});
});
});
6 changes: 3 additions & 3 deletions packages/nestjs-jwt/src/services/jwt-sign.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe(JwtSignService, () => {
throw new Error();
});
const t = async () => await jwtSignService.signAsync(access, token);
expect(t).rejects.toThrowError();
await expect(t).rejects.toThrowError();
});
});

Expand All @@ -51,7 +51,7 @@ describe(JwtSignService, () => {
throw new Error();
});
const t = async () => await jwtSignService.verifyAsync(access, token);
expect(t).rejects.toThrowError();
await expect(t).rejects.toThrowError();
});
});

Expand All @@ -67,7 +67,7 @@ describe(JwtSignService, () => {
throw new Error();
});
const t = async () => await jwtSignService.decode(access, token);
expect(t).rejects.toThrowError();
await expect(t).rejects.toThrowError();
});
});

Expand Down
4 changes: 2 additions & 2 deletions packages/nestjs-jwt/src/services/jwt-verify.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe(JwtVerifyService, () => {
throw new Error();
});
const t = async () => await jwtVerifyService.accessToken(token);
expect(t).rejects.toThrowError();
await expect(t).rejects.toThrowError();
});
});

Expand All @@ -43,7 +43,7 @@ describe(JwtVerifyService, () => {
throw new Error();
});
const t = async () => await jwtVerifyService.refreshToken(token);
expect(t).rejects.toThrowError();
await expect(t).rejects.toThrowError();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ describe(PasswordStorageService, () => {
await storageService.hashObject({}, { required: true });
};

expect(t).rejects.toThrow(Error);
expect(t).rejects.toThrow(
await expect(t).rejects.toThrow(Error);
await expect(t).rejects.toThrow(
'Password is required for hashing, but non was provided.',
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe(LookupService, () => {
throw new Error();
});

expect(testLookupService['findOne']({})).rejects.toThrow(
await expect(testLookupService['findOne']({})).rejects.toThrow(
ReferenceLookupException,
);
});
Expand Down
24 changes: 12 additions & 12 deletions packages/typeorm-common/src/services/mutate.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ describe(MutateService, () => {
return testMutateService.create({ firstName: 'Bob' });
};

expect(t).rejects.toThrow(ReferenceMutateException);
await expect(t).rejects.toThrow(ReferenceMutateException);
});

it('invalid', async () => {
const t = async () => {
return testMutateService.create({ firstName: 'B' });
};

expect(t).rejects.toThrow(ReferenceValidationException);
await expect(t).rejects.toThrow(ReferenceValidationException);
});
});

Expand Down Expand Up @@ -113,7 +113,7 @@ describe(MutateService, () => {
});
};

expect(t()).rejects.toThrow(ReferenceIdNoMatchException);
await expect(t()).rejects.toThrow(ReferenceIdNoMatchException);
});

it('found but not valid', async () => {
Expand All @@ -125,7 +125,7 @@ describe(MutateService, () => {
});
};

expect(t).rejects.toThrow(ReferenceValidationException);
await expect(t).rejects.toThrow(ReferenceValidationException);
});

it('found, valid, but exception on save', async () => {
Expand All @@ -143,7 +143,7 @@ describe(MutateService, () => {
});
};

expect(t).rejects.toThrow(ReferenceMutateException);
await expect(t).rejects.toThrow(ReferenceMutateException);
});
});

Expand Down Expand Up @@ -184,7 +184,7 @@ describe(MutateService, () => {
});
};

expect(t).rejects.toThrow(ReferenceIdNoMatchException);
await expect(t).rejects.toThrow(ReferenceIdNoMatchException);
});

it('found but not valid', async () => {
Expand All @@ -197,7 +197,7 @@ describe(MutateService, () => {
});
};

expect(t).rejects.toThrow(ReferenceValidationException);
await expect(t).rejects.toThrow(ReferenceValidationException);
});

it('found, valid, but exception on save', async () => {
Expand All @@ -216,7 +216,7 @@ describe(MutateService, () => {
});
};

expect(t).rejects.toThrow(ReferenceMutateException);
await expect(t).rejects.toThrow(ReferenceMutateException);
});
});

Expand All @@ -234,7 +234,7 @@ describe(MutateService, () => {
return testMutateService['findById'](testObject.id);
};

expect(t).rejects.toThrow(ReferenceIdNoMatchException);
await expect(t).rejects.toThrow(ReferenceIdNoMatchException);
});

it('id does not match', async () => {
Expand All @@ -244,7 +244,7 @@ describe(MutateService, () => {
});
};

expect(t).rejects.toThrow(ReferenceIdNoMatchException);
await expect(t).rejects.toThrow(ReferenceIdNoMatchException);
});

it('exception', async () => {
Expand All @@ -260,7 +260,7 @@ describe(MutateService, () => {
throw new Error();
});

expect(t).rejects.toThrow(ReferenceMutateException);
await expect(t).rejects.toThrow(ReferenceMutateException);
});
});

Expand All @@ -278,7 +278,7 @@ describe(MutateService, () => {
throw new Error();
});

expect(t).rejects.toThrow(ReferenceLookupException);
await expect(t).rejects.toThrow(ReferenceLookupException);
});
});
});

0 comments on commit f28ce25

Please sign in to comment.