I am currently working with Angular 11 using TypeScript and I am unsure how to properly test scenarios where an exception is raised within my method.
myMethod() {
this.myService.callBackend(id).subscribe(() => {
// do something when success
}, responseKo => {
if (responseKo instanceof HttpErrorResponse) {
if (responseKo.status === 400) {
// do something when we have bad request
} else {
throw responseKo;
}
} else {
throw responseKo;
}
});
}
For testing, I am utilizing the jasmine and karma frameworks. How can I effectively test the scenario in which an exception is thrown?