spy.and.throwError() - throw error as object?

685 Views Asked by At

is there any way to throw an error as an object in jasmine? In my productive code i use the error object (that comes from request promise native) to log some information. And then i have a logger spy, that checks if the error was logged correctly. But when my test throws the error with a simple error message and my productive code wants to access err.response.headers i get a runtime error.

i already tried to use it like this

spy.and.throwError(new Error({...}))

But as the constructor from Error only takes a string as argument, it obviously does not work

1

There are 1 best solutions below

0
Felix On

spy.and.returnValue(Promise.reject({message: 'someError', response: {headers: 'abc'}}));

solved the problem