Jest unit testing no longer works with Ionic 4 beta 9-11
See original GitHub issueBug Report
Ionic Info
Run ionic info from a terminal/cmd prompt and paste the output below.
Ionic:
ionic (Ionic CLI) : 4.1.2
Ionic Framework : @ionic/angular 4.0.0-beta.11
@angular-devkit/core : 0.8.3
@angular-devkit/schematics : 0.8.3
@angular/cli : 6.2.3
@ionic/ng-toolkit : 1.0.7
@ionic/schematics-angular : 1.0.6
Cordova:
cordova (Cordova CLI) : 7.1.0
Cordova Platforms : none
Cordova Plugins : no whitelisted plugins (0 plugins total)
System:
Android SDK Tools : 26.1.1 (/Users/rc101077/Library/Android/sdk)
ios-deploy : 2.0.0
ios-sim : 7.0.0
NodeJS : v8.11.4 (/Users/rc101077/.nvm/versions/node/v8.11.4/bin/node)
npm : 6.4.1
OS : macOS High Sierra
Xcode : Xcode 9.4.1 Build version 9F2000
Describe the Bug Jest unit testing no longer works with Ionic 4 beta 9. An error appears for each spec file that relies on Ionic as such:
Cannot find module '@ionic/core/loader' from 'app-initialize.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
at Object.<anonymous> (node_modules/@ionic/angular/dist/app-initialize.js:1:1)
Steps to Reproduce Steps to reproduce the behavior:
- Create an Ionic project with a Jest unit test setup (Jest version 22+)
- Run the unit tests
- See the error above for every file using Ionic imports
Expected Behavior There should be no errors and all the unit tests should pass.
Additional Context This looks to be broken with Ionic 4 beta 9, 10 and 11. It works fine in beta 8.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:37 (13 by maintainers)
Top Results From Across the Web
Unit testing ionic services with jest - Stack Overflow
I'm building an ionic app and would like to add unit tests for a couple of services. I'm trying to get jest working...
Read more >Unit testing an Ionic application with the Jest testing framework
Over the course of this tutorial I'm going to take you through how to install, configure and use Jest to run unit tests...
Read more >Xdo - River Thames Conditions - Environment Agency - GOV.UK
Frascio planeo, Haberli deer processing, How 10 pin bowling scoring works, Bench source ... No more war no more clothes, Julie mehretu drawings,...
Read more >How to setup Jest in an Ionic 4 project | by Gregor Woiwode
The tests of app.component.spec.ts cannot be executed. If you try to import @ionic/angular the test runner raises an error because of a ...
Read more >Angular Unit and End-to-End Testing for Ionic App Components
When an @ionic/angular application is generated using the Ionic CLI, it is automatically set up for unit testing and end-to-end testing of the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

FYI, this problem still exists in Ionic beta 12. But in addition, the same tests in beta 12 now show this error:
I’ve tried adding
"^@ionic/angular": "<rootDir>/node_modules/@ionic/angular/dist/index",to themoduleNameMapperof Jest, but that just changes the error to:For now, I’m reverting back to beta 11 until a solution can be found.
I experience the same issue. Since
jest-preset-angularreceived a major update to version 7 russcarver/ionic4-project-template stopped working for me.I spent a little time investigating the problem and set up a new ionic project using the following package-versions
Here is the sample repository: GregOnNet/ionic-4-jest-setup
I wrote a small article discussing why @ionic/angular fails to run with Jest: How to set up Jest in an Ionic 4 project
I am glad if this helps somebody.