Unable to run unit test on ionic 2

I other to unit test my app, I’ve follow this Ionic 2 unit test tutorial.
When I run the command:
npm test

I have this output.

 ng test
It seems like you're using a project generated using an old version of the Angular CLI.
The latest CLI now uses webpack and has a lot of improvements including a simpler
workflow, a faster build, and smaller bundles.

To get more info, including a step-by-step guide to upgrade the CLI, follow this link:

npm ERR! Test failed.  See above for more details.

Here is my config

"dependencies": {
"@angular/common": “2.2.1”,
"@angular/compiler": “2.2.1”,
"@angular/compiler-cli": “2.2.1”,
"@angular/core": “2.2.1”,
"@angular/forms": “2.2.1”,
"@angular/http": “2.2.1”,
"@angular/platform-browser": “2.2.1”,
"@angular/platform-browser-dynamic": “2.2.1”,
"@angular/platform-server": “2.2.1”,
“angular2-moment”: “^1.0.0-beta.rc.1”,
“moment”: “^2.16.0”,
“ng2-translate”: “^5.0.0”,
“socket.io-client”: “^1.5.1”,
"@ionic/storage": “1.1.7”,
“ionic-angular”: “2.0.0”,
“ionic-native”: “2.4.1”,
“ionicons”: “3.0.0”,
“rxjs”: “5.0.0-beta.12”,
“zone.js”: “0.6.26”
“devDependencies”: {
"@ionic/app-scripts": “latest”,
"@types/jasmine": “^2.5.42”,
"@types/node": “^7.0.5”,
“angular-cli”: “^1.0.0-beta.20-1”,
“codecov”: “^1.0.1”,
“jasmine-core”: “^2.5.2”,
“jasmine-spec-reporter”: “^3.2.0”,
“karma”: “^1.4.1”,
“karma-chrome-launcher”: “^2.0.0”,
“karma-jasmine”: “^1.1.0”,
“karma-mocha-reporter”: “^2.2.2”,
“karma-remap-istanbul”: “^0.6.0”,
“sw-toolbox”: “^3.4.0”,
“ts-node”: “^2.1.0”,
“tslint”: “^4.4.2”,
“tslint-eslint-rules”: “^3.3.0”,
“typescript”: “^2.0.3”

1 Like

I had the same issue, to fix it I had to

1. update ionic cli to the latest version
2. create a new project: https://ionicframework.com/docs/v2/intro/installation/
3. replace the src directory in the new project with your existing one (delete src/app/main.dev.ts, main.prod.ts if you have them, you don’t need them in the newer versions)
4. set up the testing environment: https://www.joshmorony.com/introduction-to-testing-ionic-2-applications-with-testbed/ or https://github.com/lathonez/clicker
5. ng test


I found out the tests were working because I had the latest @angular/cli installed globally, and I was running the commands with ng test. I am still trying to make it work with local version. By then try to npm install -g @angular/cli and then ng test