'Is there some way to test the inner implementation when response in Observable is 500 (Error occured)
Here is the code below
@Output() hitCodeReturned = new EventEmitter<boolean>();
ngOnInit() {
this.someService.method().subscribe(
() => {
// Some code here
},
({ error }) => {
if (condition equals true) {
this.hitCodeReturned.emit(true);
}
}
);
}
The test should ensure that true will be emitted when response will return error with some body
Solution 1:[1]
yes, just use throwError operator in test
//in jasmine/karma test
//assuming that someService is a `mock`
it('propagates hitCodeReturned', (done)=>{
someService.and.return(throwError("here you can throw any kind of error"));
component.hitCodeReturned().subscribe(code=>{
expect(code).toBeTrue();
done();
});
component.ngOnInit();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
