Skip to content

How to mock catchError #227

@ascdi

Description

@ascdi

i am trying to test a path that leads into an rxjs catchError function.

Example Code:

    return next.handle(request).pipe(
      catchError((error: HttpErrorResponse) => {
        console.log(`test`);

Now i am Mocking the next Part using mock & instance and tried both thenThrow and thenReturn(throwError( in Order to throw an error that could be catched by catchError. But i never reach the console.log statement.

Example:

    when(mockHttpHandler.handle(anything())).thenReturn(
      throwError(
        new HttpErrorResponse({
          error: 'some cryptic error called 93457tz9w345hzg9w24phg9ow4jh',
          url: testUrl,
          status: 500,
        })
      )
    );

How can i reach that path, mocking my next.handle?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions