Angular5 / ng test ERROR : TypeError: this.handler.handle is not a function

For me, this issue came from trying to include HttpClient and HttpHandler in my providers like so:

providers: [
    HttpClient,
    HttpHandler
]

This kept throwing errors along the lines of _TypeError: this.handle.handler is not a function

To fix this, I found I could remove HttpClient and HttpHandler from the providers and instead add HttpClientTestingModule to my imports like so:

imports: [
    HttpClientTestingModule
]

This solved this particular error for me in my Karma unit tests for Angular 7.


Please add error handler in your component.ts where you are calling this login(credentials) method.

user_login() {
this.userService.login(credentials).subscribe((res) => {
console.log(res);
}, (error) => {
console.log(error);
});