When running with npm test i get the following error
FAIL src/tests/DoSomething.test.ts
โ Test suite failed to run
Cannot find module 'core-js/es6/reflect' from 'setupJest.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:203:17)
at Object.<anonymous> (node_modules/jest-preset-angular/setupJest.js:3:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.956s
Ran all test suites.
npm ERR! Test failed. See above for more details.
Can you check if you have core-js in your package.json in dependencies? A newly generated Angular project should have it. After npm install there obviously should be a node_modules/core-js as well. Check if it contains es6/reflect.
Also your versions of
this is my package.json
{
"name": "testApp",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"start": "ionic-app-scripts serve",
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"test": "jest",
"test:watch": "jest --watch",
"test:ci": "jest --runInBand"
},
"dependencies": {
"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
"@angular/forms": "5.2.11",
"@angular/http": "5.2.11",
"@angular/platform-browser": "5.2.11",
"@angular/platform-browser-dynamic": "5.2.11",
"@ionic-native/core": "~4.18.0",
"@ionic-native/file": "^4.18.0",
"@ionic-native/splash-screen": "~4.18.0",
"@ionic-native/status-bar": "~4.18.0",
"@ionic/storage": "2.2.0",
"@types/jest": "^24.0.0",
"cordova-android": "7.0.0",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-file": "^6.0.1",
"cordova-plugin-ionic-keyboard": "^2.1.3",
"cordova-plugin-ionic-webview": "^3.1.1",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-whitelist": "^1.3.3",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"jest": "^24.1.0",
"jest-preset-angular": "^6.0.2",
"rxjs": "5.5.11",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.29"
},
"devDependencies": {
"@ionic/app-scripts": "3.2.1",
"@ionic/lab": "1.0.20",
"typescript": "~2.6.2"
},
"jest": {
"preset": "jest-preset-angular",
"setupFilesAfterEnv": ["<rootDir>/src/setupJest.ts"]
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-file": {},
"cordova-plugin-whitelist": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {
"ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
},
"cordova-plugin-ionic-keyboard": {}
},
"platforms": [
"android"
]
}
}
but didn't find core-js in my node modules. It is an ionic project. But don't think that should matte?
A newly created ionic project should include core-js as dependency, as can be seen in a new project created using the ionic cli and ionic start myapp blank.
Just go ahead and add it to your project using npm install --save-dev core-js.
Please close this issue if this solved your problem.
Cheers!
it solved the first issue but now i get this:
Cannot find module './jestGlobalMocks' from 'setupJest.ts'
1 | import 'jest-preset-angular';
> 2 | import './jestGlobalMocks';
| ^
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:203:17)
at Object.<anonymous> (src/setupJest.ts:2:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 2.426s
Ran all test suites.
npm ERR! Test failed. See above for more details.
Please read the instruction in our README.md, especially about Usage and Troubleshooting before opening an issue here. Your second issue is documented there.
I am having the same issue regarding core-js
I attempted to install core-js manually and it did not solve my issue.
I am working with Ionic as well (version 3.9.3).
Angular version: 5.2.11
core-js version: 3.9.3
Jest version: 24.5.0
jest-preset-angular version: 7.0.1
What do you mean by 'the same issue'?
Do you not have core-js installed either? How do you have the version 3.9.3?
If setupJest or jestGlobalMocks is missing, make sure you setup the preset as described in our README.md.
@theAndrewCline I have the same problem too though I'm not using ionic. I'm using nx. The package is definitely installed (version "^3.0.0").
How did you solve this?
core-js@3 had a major API change. There are no imports available through core-js/es6 anymore.
Please see https://github.com/zloirock/core-js/blob/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md for more information.
A fix is to lock core-js down to v2 or to adjust the imports.
We have not upgraded jest-preset-angular yet, feel free to open a PR if you want to help out.
Ok, I see, it is actually an issue on our end. I created a new issue regarding it.
See #244 for further discussion.
@wtho Thanks for looking into this, it took forever to find my way to this issue, so confusing...
What do you mean by 'the same issue'?
Do you not havecore-jsinstalled either? How do you have the version3.9.3?If
setupJestorjestGlobalMocksis missing, make sure you setup the preset as described in our README.md.
I made a typo, I have 3.0.0
I installed version 2 of core-js and tests are running normally now.
Most helpful comment
I installed version 2 of core-js and tests are running normally now.