I am doing unit test in Angular 5.
With the new http module, I know that I can mock response data by using flush
method in HttpTestingController
, but how can I mock an error (I want to test my error handler)?
Use error
rather than flush
httpTestingController.expectOne(url).error(errorEvent);
or pass a status to flush:
httpTestingController.expectOne(url).flush(null, {status: 400, statusText: "Bad Request"});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With