I'm working on writing unit tests for my ionic 2 app, and I have a @ViewChild call that looks like this:
<ion-slides #slides (ionSlideDidChange)="onSlideChanged()" pager>
and in my slides.ts I have this:
@ViewChild(Slides) slides: Slides;
This works fine when running the server, and the slides work great, but when I try and write a unit test, slides is undefined. This, of course, breaks everything else.
My unit test setup looks like this:
beforeEach(async(() => TestUtils.beforeEachCompiler([HomePage]).then(compiled => {
fixture = compiled.fixture;
component = compiled.instance;
component.ngOnInit();
})));
it('should have a defined component', () => {
// The next line is where it starts throwing the errors.
fixture.detectChanges();
expect(component).toBeDefined();
});
What can I do to get my @ViewChild defined correctly in a unit test?