I am trying to test a page in Ionic 3. So, I created .spec.ts of that page manually within src/pages/page folder. But when I create component using TestBed.createComponent, then it shows following error :
about.spec.ts file
import { CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
import { TestBed, ComponentFixture, async } from "@angular/core/testing";
import { AboutPage } from './about';
import { IonicPageModule, NavController, NavParams, Platform } from 'ionic-angular';
import { BrowserDynamicTestingModule,platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
describe('AboutPage', () => {
let fixture;
let component;
beforeEach(async(() => {
TestBed.resetTestEnvironment();
TestBed.initTestEnvironment(BrowserDynamicTestingModule,platformBrowserDynamicTesting());
TestBed.configureTestingModule({
declarations: [ AboutPage ],
imports: [IonicPageModule.forChild(AboutPage)],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [NavController, NavParams, Platform]
}).compileComponents().then((response) => {
fixture = TestBed.createComponent(AboutPage);
component = fixture.componentInstance;
fixture.detectChanges();
});
}));
afterEach(() => {
fixture.destroy();
component = null;
});
describe('First test',() => {
it('should print',() => {
let a = true;
expect(a).toBeTruthy();
})
})
});
I am unable to find out where my code is lacking due to which this error is coming. I need to fetch component in my spec file so as to perform testing on its functions and its part. Please suggest where I may be doing wrong.
Aucun commentaire:
Enregistrer un commentaire