How to unit test Ionic 3 lazy loadable pages?


#1

Really confused on this. I upgraded to Ionic 3 and converted some pages to lazy loading and, of course, it breaks my test setup completely. My test setup was based on the DriftyCo testing example.


#2

no pages import in app.module.ts , and importing in respective page module and set root as string in app component.ts…
read the following link for exact way.


#3

My code is working fine, what I’m asking is how to actually unit test a lazy loadable page module. In the DriftyCo and other examples, you’d set up an Angular TestBed declaring the page, imports (including IonicModule.forRoot(MyPage).
Then, in a beforeEach, you’d create the page via TestBed.createComponent.
None of this works now, of course, as pages are referenced in a different way - injection errors, etc.

I’m looking for a solid example of testing a lazy loadable page - how to use the TestBed, etc. I’m guessing you need to reference myApp instead of the page directly and request the page from there, but I’m just not sure how to go about it.


#4

Did you get any where with this?


#5

I did, actually! Wasn’t too bad, there was just a few changes I needed to make to get this to go. Everything working well now.
If you’re interested, I could post some of the code to help you out - just not right at my fingertips at this second…let me know.


#6

@spiraljacobs I’m definitely interested in this. I thought that changing forRoot to forChild and importing IonicPageModule instead would be the fix, but still not working. Could you state what you needed to change? Thanks!


#7

@spiraljacobs I’m also got (and still am ) stuck on unit testing for lazy load pages.
If you have a working example, or a snipit that shows how to test a page, I would greatly appreciate that.

Thank you in advance,
Roy


#8

Really could use a working example! Still stuck in trying to get it work. Did you leave in the IonicModule.forRoot or did you use the IonicPageModule? … Do you have it working with a translateService?