'how to test interceptor of http errors in nestjs
I have implemented this interceptor that transform http errors,
@Injectable()
export class SolverInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
// next.handle() is an Observable of the controller's result value
return next.handle()
.pipe(catchError(error => {
if (error.response.data.method_response.status === AppFrameworkStatus.USER_ERROR) {
const response: RawJobMethodResponse = error.response.data.method_response;
throw new InvalidSolverDataException(response);
} else {
const response: RawJobMethodResponse = error.response.data.method_response;
throw new InvalidSolverDataException(response);
}
}));
}
}
but i don't know how to test it correctly, i have tried testing like shown below but i am not sure about it , please help
it('it should call', async () => {
callHandler.handle.mockResolvedValueOnce('next handle');
const actualValue = interceptor.intercept({} as any, { handle: () => of(error) });
actualValue.subscribe({
next: (val) => {
expect(val).toBeInstanceOf(InvalidSolverDataException)
},
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
