2

In my Angular 4 application I need to create a test for a component which uses a service which internally uses the angular HttpClient.

Despite I added HttpClientTestingModule between the imports of my TestBed, I get:

TypeError: Cannot read property 'get' of undefined

whenever the component calls MyService.someMethod() (which internally uses HttpClient.get()).

I tried providing the service itself or providing a mock for it, but I'm getting the error anyway.

1 Answer 1

4

I found the problem:

I needed to remove { provide: AuthService, useClass: MockAuthService }, from my TestBed's providers list. It is no longer needed and somehow was interfering with the HttpClientTestingModule.

Sign up to request clarification or add additional context in comments.

1 Comment

I only have this code in spec file: providers: [{provide: http}], But still getting the same error, any idea ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.