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

bug: ionic angular, karma tests not waiting for ionic to load on live-reloads #22853

Closed
bohndthi opened this issue Feb 2, 2021 · 12 comments
Closed
Labels
package: angular @ionic/angular package type: bug a confirmed bug report
Milestone

Comments

@bohndthi
Copy link

bohndthi commented Feb 2, 2021

Bug Report

Ionic version:
[x] 5.x

Current behavior:
If a page contains an ion-segment, the karma tests throws an long error message:

Chrome Headless 88.0.4324.50 (Linux x86_64): Executed 2 of 111 (1 FAILED) (0 secs / 0.339 secs)
ERROR: TypeError: config.get is not a function
TypeError: config.get is not a function
    at addEventListener (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@ionic/core/dist/esm/helpers-90f46169.js:29:1)
    at SegmentButton.connectedCallback (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@ionic/core/dist/esm/ion-segment_2.entry.js:375:23)
    at safeCall (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@ionic/core/dist/esm/index-e806d1f6.js:1261:1)
    at fireConnectedCallback (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@ionic/core/dist/esm/index-e806d1f6.js:1687:1)
    at initializeComponent (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@ionic/core/dist/esm/index-e806d1f6.js:1650:1)
    at http://localhost:9876/_karma_webpack_/webpack:/node_modules/@ionic/core/dist/esm/index-e806d1f6.js:1750:1
    at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone-evergreen.js:368:1)
    at ProxyZoneSpec.push.QpwO.ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone-testing.js:300:1)
    at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone-evergreen.js:367:1)

Expected behavior:
no long error messages
Steps to reproduce:

  • Create new project (angular)
  • add an ion-segment to a page
  • run the karma unit test for the page

Ionic info:

@ionic/angular: 5.5.3

@ionitron-bot ionitron-bot bot added the triage label Feb 2, 2021
@liamdebeasi
Copy link
Contributor

Thanks for the issue. Can you provide a GitHub repo that shows this issue happening? I have a blank starter app with an ion-segment and am unable to reproduce the issue.

@liamdebeasi liamdebeasi added the ionitron: needs reproduction a code reproduction is needed from the issue author label Feb 2, 2021
@ionitron-bot
Copy link

ionitron-bot bot commented Feb 2, 2021

Thanks for the issue! This issue has been labeled as needs reproduction. This label is added to issues that need a code reproduction.

Please reproduce this issue in an Ionic starter application and provide a way for us to access it (GitHub repo, StackBlitz, etc). Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed.

If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for our team to reproduce the issue.

For a guide on how to create a good reproduction, see our Contributing Guide.

@ionitron-bot ionitron-bot bot removed the triage label Feb 2, 2021
@bohndthi
Copy link
Author

Hey @liamdebeasi, thanks for the quick response. I now realized that the error only occurs under certain conditions:
you either have to:

  • run the tests in watch mode, the error occurs at the second run and onwards
  • have two ion-segments in your project (for example in the tabs starter app on tab1 and tab2)

i is rather complicated for me to share a project via github since i am in a corporate network. If you still have issues reproducing it, please let me now.

@liamdebeasi
Copy link
Contributor

Sorry for the delay. Are you able to reproduce this in an Ionic starter app and share a link if possible? I tried adding 2 ion-segment instance and ran the tests in watch mode a few times, but I cannot get the error to reproduce.

@bohndthi
Copy link
Author

Hi @liamdebeasi, please have a look at https://github.com/bohndthi/ionic-bug

@liamdebeasi
Copy link
Contributor

Thanks! I can reproduce this. The issue seems to be that the tests are not waiting for Ionic Angular to be fully configured when live-reloading the Karma tests. On first test load, config.get is defined as well as the rest of the config, but on subsequent live-reloads, neither config.get nor the rest of the config seems to be setup yet.

@liamdebeasi liamdebeasi changed the title bug: Karma throws tons of errors if the app contains an ion-segment bug: ionic angular, karma tests not waiting for ionic to load on live-reloads Feb 25, 2021
@liamdebeasi liamdebeasi added package: angular @ionic/angular package type: bug a confirmed bug report and removed ionitron: needs reproduction a code reproduction is needed from the issue author labels Feb 25, 2021
@Spinnenzunge
Copy link

Same happens for me with ion-radio

@sunnydrall
Copy link

Is there any update?

1 similar comment
@jordanorc
Copy link

Is there any update?

@studioromeo
Copy link
Contributor

Has anyone developed a workaround to this issue?

studioromeo added a commit to studioromeo/ionic that referenced this issue Oct 1, 2021
When karma runs each test case the window object persists. Ionic does
some initial setup in angular first before handing over to core.

On each test case in karma angular bootstraps itself again, during this
bootstrap we set Ionic.config. On the first test case this is fine as Ionic
core is also bootstrapped but on the second test case this overwrites
legitimate config which causes parts of Ionic to fail as the config is
no longer in the expected format.

This fix works by only setting Ionic.config if it does not already
exist. If it does exist then we do not replace it with an object thats
not compatible with core.

There may be better ways to solve this issue but I didn't want to change
too much of ionic/angular so this felt like the safest change
@liamdebeasi liamdebeasi added type: bug a confirmed bug report and removed type: bug a confirmed bug report labels Oct 1, 2021
@liamdebeasi liamdebeasi added this to the 5.8.2 milestone Oct 4, 2021
@liamdebeasi
Copy link
Contributor

Thanks for the issue. This has been resolved via #24004, and a fix will be available in an upcoming release of Ionic Framework.

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 3, 2021

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: angular @ionic/angular package type: bug a confirmed bug report
Projects
None yet
Development

No branches or pull requests

6 participants