1

I am trying to setup the Angular2 project with unit tests. I am using this manual: http://twofuckingdevelopers.com/2016/01/testing-angular-2-with-karma-and-jasmine/ It is obviously outdated, because now default Angular2 npm package is @angular/*

The stated example doesn't work, because angular2 package is different. So I am re-mapping everything to that @angular package.

My package.json contains the following dependencies:

"dependencies": {
"@angular/common": "^2.0.0-rc.5",
"@angular/compiler": "^2.0.0-rc.5",
"@angular/core": "^2.0.0-rc.5",
"@angular/http": "^2.0.0-rc.5",
"@angular/platform-browser": "^2.0.0-rc.5",
"@angular/platform-browser-dynamic": "^2.0.0-rc.5",
"@angular/router": "^3.0.0-rc.1",
"@angular/router-deprecated": "^2.0.0-rc.2",
"@angular/upgrade": "^2.0.0-rc.5",
"es6-promise": "^3.2.1",
"es6-shim": "^0.35.1",
"reflect-metadata": "^0.1.2",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.17"
},
"devDependencies": {
"@angular/testing": "^0.0.0-0",
"concurrently": "^2.0.0",
"eslint": "^3.3.1",
"eslint-config-google": "^0.6.0",
"eslint-config-standard": "^6.0.0",
"eslint-plugin-promise": "^2.0.1",
"eslint-plugin-standard": "^2.0.0",
"jasmine-core": "2.4.1",
"karma": "^1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.0.2",
"lite-server": "^2.2.0",
"remap-istanbul": "^0.6.4",
"typescript": "^1.8.10",
"typings": "^1.0.4"
}

I deleted all node_packages folder to start from clean slate.

When running "npm install", I see the following output:

$ npm install
npm WARN package.json testing-from-twofuckingdevelopers.com@1.0.0 No description
npm WARN package.json testing-from-twofuckingdevelopers.com@1.0.0 No repository field.
npm WARN package.json testing-from-twofuckingdevelopers.com@1.0.0 No README data
npm WARN deprecated tough-cookie@2.2.2: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130
npm WARN peerDependencies The peer dependency @angular/core@0.0.0-0 included from @angular/testing will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency 
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
npm WARN peerDependencies The peer dependency @angular/common@0.0.0-0 included from @angular/testing will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency 
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
npm WARN peerDependencies The peer dependency @angular/compiler@0.0.0-0 included from @angular/testing will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency 
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
npm WARN peerDependencies The peer dependency @angular/platform-browser@0.0.0-0 included from @angular/testing will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency 
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
|
> fsevents@1.0.14 install /Users/maris/Dropbox/Documents/Knowledge/Development/Angular2/testing-from-twofuckingdevelopers.com/node_modules/karma/node_modules/chokidar/node_modules/fsevents
> node-pre-gyp install --fallback-to-build

[fsevents] Success: "/Users/maris/Dropbox/Documents/Knowledge/Development/Angular2/testing-from-twofuckingdevelopers.com/node_modules/karma/node_modules/chokidar/node_modules/fsevents/lib/binding/Release/node-v46-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile

> fsevents@1.0.14 install /Users/maris/Dropbox/Documents/Knowledge/Development/Angular2/testing-from-twofuckingdevelopers.com/node_modules/lite-server/node_modules/browser-sync/node_modules/chokidar/node_modules/fsevents
> node-pre-gyp install --fallback-to-build

[fsevents] Success: "/Users/maris/Dropbox/Documents/Knowledge/Development/Angular2/testing-from-twofuckingdevelopers.com/node_modules/lite-server/node_modules/browser-sync/node_modules/chokidar/node_modules/fsevents/lib/binding/Release/node-v46-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v4.5.0
npm ERR! npm  v2.15.9
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package @angular/common@2.0.0-rc.5 does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer @angular/platform-browser@2.0.0-rc.5 wants @angular/common@^2.0.0-rc.5
npm ERR! peerinvalid Peer @angular/platform-browser-dynamic@2.0.0-rc.5 wants @angular/common@^2.0.0-rc.5
npm ERR! peerinvalid Peer @angular/router@3.0.0-rc.1 wants @angular/common@^2.0.0-rc.5
npm ERR! peerinvalid Peer @angular/router-deprecated@2.0.0-rc.2 wants @angular/common@^2.0.0-rc
npm ERR! peerinvalid Peer @angular/testing@0.0.0-0 wants @angular/common@0.0.0-0

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/maris/Dropbox/Documents/Knowledge/Development/Angular2/testing-from-twofuckingdevelopers.com/npm-debug.log

What I should do to get it work? Or maybe you can suggest the tutorial that covers unit testing which works for most recent Angular2 version?

vitr
  • 6,766
  • 8
  • 30
  • 50
Maris
  • 664
  • 1
  • 5
  • 15
  • I know that "inject" is now a part of @angular/core/testing, but I don't really know where is the rest of the old test stuff... – Alex Beugnet Aug 26 '16 at 09:37

4 Answers4

1

Update the npm by using following command

npm install npm -g
Prashant
  • 276
  • 3
  • 13
0

I believe you should follow this guide on the angular.io website, which tells you about jasmine-core and how to install it with npm. With that library you should be able to do the testing you are trying to setup.

https://angular.io/docs/ts/latest/guide/testing.html

Alex Beugnet
  • 4,003
  • 4
  • 23
  • 40
  • I have done that tutorial, but if you look at it, it covers just the in-browser tesing in Jasmine, and is not finished for the CI with karma. And I cannot get those other karma samples work with that tutorial either. – Maris Aug 26 '16 at 09:42
  • I don't know much about Karma testing, but I found this post that talk about it and it seems more up to date. http://stackoverflow.com/questions/37167086/issues-getting-karma-to-work-with-systemjs-angular2-and-typescript – Alex Beugnet Aug 26 '16 at 09:48
0

I find it easier to run tests using karma-webpack.

See this commit for how I have set up tests for angular2 lib https://github.com/tb/ng2-api/commit/ef73d95b516579d7aaa9b8b55c906d140abcf3ab

The setup is scoped down version of angular2-webpack starter https://github.com/preboot/angular2-webpack

tomaszbak
  • 8,247
  • 4
  • 44
  • 37
0

Angular2 CLI solved an issue: https://cli.angular.io

It has all the testing working.

Maris
  • 664
  • 1
  • 5
  • 15