'Error testing any component with Ionic ion-infinite-scroll as child (Ionic 4)
First off, this isn't a breaking issue, but I do not like the fact that running my unit tests is presenting an error. So anyways, if you create a page/component with Ionic and use the ion-infinite-scroll component, and then proceed to unit test this component, there will always be an error such as this:
An error was thrown in afterAll
Uncaught TypeError: Cannot read property 'apply' of undefined thrown
Now this won't fail the test suite but it does show in the console and muddies it up. I have tried to mock this child component using ng-mocks but this still seems to present itself. I am using spectator with the default setup with Jasmine. I do not think this issue is related to using these tools. Does anyone have any idea on how to properly mock the ion-infinite-scroll component so test suite does not call methods on the actual component?
Here is what I've tried:
describe('SomePage', () => {
let spectator: Spectator<SomePage>;
const infiniteScrollStub = {
complete: jasmine.createSpy('complete')
};
const createComponent = createRoutingFactory({
component: SomePage,
declarations: [
IonInfiniteScroll
],
providers: [
{ provide: IonInfiniteScroll, useValue: infiniteScrollStub }
],
params: {}
});
beforeEach(() => spectator = createComponent());
it('should create', () => {
expect(spectator.component).toBeTruthy();
});
});
===
An error was thrown in afterAll
Uncaught TypeError: Cannot read property 'apply' of undefined thrown
describe('SomePage', () => {
let spectator: Spectator<SomePage>;
const infiniteScrollStub = {
complete: jasmine.createSpy('complete')
};
const createComponent = createRoutingFactory({
component: SomePage,
declarations: [
MockComponent(IonInfiniteScroll)
],
params: {}
});
beforeEach(() => spectator = createComponent());
it('should create', () => {
expect(spectator.component).toBeTruthy();
});
});
===
Error: Multiple components match node with tagname ion-infinite-scroll
The test passes on the first example with the ugly error at the end. The test fails on the second example with that reason.
Any ideas?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
