Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property '_getPortal' of undefined when testing a function that uses ToastController .present() #206

Closed
kamok opened this issue Jan 6, 2017 · 1 comment

Comments

@kamok
Copy link

kamok commented Jan 6, 2017

When you have a toast that you present(), it throws this _getPortal error. Here's a basic function that you can invoke in a spec.

private presentToast(message: string): void {
    const toast = this.toastCtrl.create({
      message: message
    });
    toast.present();
  }

There's a stackoverflow post on it, using the technique of mocking the View Controller, which according to the OP, works.

But it hasn't worked for me using the clicker template, even though it uses the same mock. Any thoughts? Can anyone else replicate?

Here's the full error:


 TypeError: Cannot read property '_getPortal' of undefined
          at App.present (webpack:///Users/kamok/code/election/election-mobile/~/ionic-angular/components/app/app.js:78:0 <- src/test.ts:2354:35)
          at Toast.present (webpack:///Users/kamok/code/election/election-mobile/~/ionic-angular/components/toast/toast.js:36:0 <- src/test.ts:62146:26)
          at CheckInPage.presentToast (webpack:///Users/kamok/code/election/election-mobile/src/pages/check-in/check-in.ts:9:7402 <- src/test.ts:47767:7371)
          at CheckInPage.broadcastMember (webpack:///Users/kamok/code/election/election-mobile/src/pages/check-in/check-in.ts:9:7095 <- src/test.ts:47767:7063)
          at CheckInPage.onMemberSelect (webpack:///Users/kamok/code/election/election-mobile/src/pages/check-in/check-in.ts:9:4181 <- src/test.ts:47767:4149)
          at Object.<anonymous> (webpack:///Users/kamok/code/election/election-mobile/src/pages/check-in/check-in.spec.ts:44:15 <- src/test.ts:77420:22)
          at ZoneDelegate.invoke (webpack:///Users/kamok/code/election/election-mobile/~/zone.js/dist/zone.js:232:0 <- src/test.ts:112459:26)
          at ProxyZoneSpec.onInvoke (webpack:///Users/kamok/code/election/election-mobile/~/zone.js/dist/proxy.js:79:0 <- src/test.ts:48591:39)
          at ZoneDelegate.invoke (webpack:///Users/kamok/code/election/election-mobile/~/zone.js/dist/zone.js:231:0 <- src/test.ts:112458:32)
          at Zone.run (webpack:///Users/kamok/code/election/election-mobile/~/zone.js/dist/zone.js:114:0 <- src/test.ts:112341:43)
@lathonez
Copy link
Owner

lathonez commented Jan 6, 2017

As discussed previously, please use stack overflow.

If you want to draw our attention to the SO post, link it in #191.

Thanks

@lathonez lathonez closed this as completed Jan 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants