1

For a series of reasons I would like to be able to test some Http services (not via mock) using Jasmine / Karma support of Angualar.

If I use the following code

beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [],
      imports: [
        HttpModule
      ]
    });
    .......

tests fail with the following message printed on Karma browser

Error: No provider for Http!
Error: DI Error
    at NoProviderError.ZoneAwareError (http://localhost:9876/base/src/polyfills.ts?1adeefc4ae1dd1c3f12dac836469652bbacab66c:2054:33)
    at NoProviderError.BaseError [as constructor] (http://localhost:9876/base/src/test.ts?5cfdb8c92873c902e956a345863bab75c6324f3e:23292:16)
    at NoProviderError.AbstractProviderError [as constructor] (http://localhost:9876/base/src/test.ts?5cfdb8c92873c902e956a345863bab75c6324f3e:47503:16)
    at new NoProviderError (http://localhost:9876/base/src/test.ts?5cfdb8c92873c902e956a345863bab75c6324f3e:47565:16)
    at ReflectiveInjector_._throwOrNull (http://localhost:9876/base/src/test.ts?5cfdb8c92873c902e956a345863bab75c6324f3e:63961:19)
.......

Any suggestion on how to fix it would be very much appreciated

1 Answer 1

1

You may need to configure the provider for Http. For example:

TestBed.configureTestingModule({
  providers: [ { provide: Http, useClass: Http } ],

If that doesn't do the trick, please share your imports and any earlier code in the test spec.

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

Comments

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.