I’m getting the following error when trying to run tests through karma:
Error: No provider for App!
at injectionError (webpack:///node_modules/@angular/core/@angular/core.es5.js:1231:21 ← test-config/karma-test-shim.js:1506:86)
at noProviderError (webpack:///node_modules/@angular/core/@angular/core.es5.js:1269:0 ← test-config/karma-test-shim.js:1544:12)
at ReflectiveInjector_._throwOrNull (webpack:///node_modules/@angular/core/@angular/core.es5.js:2770:0 …
This error happens when the following file is run:
import { AppModule } from '../../../app/ionic/ionic-app.module';
import { async, TestBed } from '@angular/core/testing';
import { App, IonicModule, PopoverController } from 'ionic-angular';
import { IonicPlayerInfoBannerComponent } from './ionic-player-info-banner';
import { PopoverControllerMock } from '../../../../test-config/mocks-ionic';
describe('IonicPlayerInfoBannerComponent Component', () => {
let fixture;
let component;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [IonicPlayerInfoBannerComponent],
providers: [
{ provide: PopoverController, useClass: PopoverControllerMock }
],
imports: [
IonicModule.forRoot(IonicPlayerInfoBannerComponent)
],
})
}));
beforeEach(() => {
fixture = TestBed.createComponent(IonicPlayerInfoBannerComponent);
component = fixture.componentInstance;
});
it('should be created', () => {
expect(component instanceof IonicPlayerInfoBannerComponent).toBe(true);
});
});
I’ve tried putting App in the providers sections of the TestBed module configuration, but I still get the same error.
I’ve also tried the following configuration with the same error (having the real root component as the root for the IonicModule import):
TestBed.configureTestingModule({
declarations: [MyApp, IonicPlayerInfoBannerComponent],
providers: [
App,
{ provide: PopoverController, useClass: PopoverControllerMock }
],
imports: [
IonicModule.forRoot(MyApp)
],
})
I cannot figure out for the life of me what I’m doing incorrectly, the test file for the main MyApp component works perfectly with this same syntax. Any help would be greatly appreciated!