Error: no provider for configuration! (Icon & # 8594; Config) in Ionic2 unit tests with karma and jasmin

I write unit tests for the ionic2 application, but I get the following error when the template contains some ionic elements for example.

<ion-icon > </ion-icon>

Failed: there is no provider to configure! (Icon → Configuration)

Any idea?

+4
source share
3 answers

you are not allowed to use the template in @app, try using templateUrl: 'build / app.html' and create app.html with your tags in it.

0
source

I am facing the same problem. This worked for me:

import { async, ComponentFixture, TestBed } from "@angular/core/testing";
import { Config, IonicModule } from "ionic-angular";

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

  fixture = TestBed.createComponent(MyComponent);
  component = fixture.componentInstance;
});
0
source

I don’t see how the previous solution works, because it Configis required App, it is required Platform, it is required Keyboard, it needs ... perhaps it is because you are not configuring the test module asynchronously, which you should;) just try the following:

import { IonicModule } from 'ionic-angular';
import { YourTestedComponent } from './pathto.component.ts'

beforeEach(async(() => {
  TestBed.configureTestingModule({
    imports: [ IonicModule.forRoot(this) ], // this loads ionic deps
    declarations: [ YourTestedComponent ],
  });
}));

That should fix it. Good luck.

0
source

All Articles