Unit test issue when using LoadingController


Hi, I’m using the LoadingController to show a message when retrieving some data, which works fine, but when I run my unit tests I get TypeError: controller.componentOnReady is not a function. I know it’s related to the LoadingController, because if I remove it from the page, the tests run fine. I did think it was because the LoadingController uses a Promise which I wasn’t fulfilling, but when I added the then statement to the LoadingController call the test still fails.

this is how I implemented the Loader:

            .create({ spinner: 'hide', message: 'Loading Messages' })
            .then(() => {

I’m not sure what the error message is trying to tell me? Can anyone shed some light on this?




Actually I’ve found out what the problem was. I needed to mock up the create and dismiss functions in my Provider for the test, like this:

 providers: [
                    provide: LoadingController,
                    useValue: {
                        create: () => Promise.resolve(),
                        dismiss: () => Promise.resolve()

The create and dismiss functions never completed because they return Promises, but failed due to the test not creating the Overlay you’d expect to see when the loader is running.