无法将@ angular / testing npm包添加到Angular2项目中

时间:2016-08-26 09:28:27

标签: angular npm-install angular2-testing

我正在尝试使用单元测试来设置Angular2项目。 我正在使用本手册:http://twofuckingdevelopers.com/2016/01/testing-angular-2-with-karma-and-jasmine/ 它显然已经过时了,因为现在默认的Angular2 npm包是@angular / *

所述示例不起作用,因为angular2包不同。 所以我将所有内容重新映射到@angular包。

我的package.json包含以下依赖项:

"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"
}

我删除了所有node_packages文件夹,从干净的平板开始。

运行" npm install"时,我看到以下输出:

$ 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

我应该怎样做才能让它发挥作用? 或者您可以建议涵盖单元测试的教程,该教程适用于最新的Angular2版本吗?

4 个答案:

答案 0 :(得分:0)

我相信你应该在angular.io网站上遵循这个指南,它告诉你关于jasmine-core以及如何用npm安装它。 使用该库,您应该能够进行您尝试设置的测试。

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

答案 1 :(得分:0)

我发现使用karma-webpack运行测试更容易。

请参阅此提交,了解我如何为angular2 lib https://github.com/tb/ng2-api/commit/ef73d95b516579d7aaa9b8b55c906d140abcf3ab

设置测试

该设置是angular2-webpack starter https://github.com/preboot/angular2-webpack

的范围

答案 2 :(得分:0)

使用以下命令

更新npm
npm install npm -g

答案 3 :(得分:0)

Angular2 CLI解决了一个问题: https://cli.angular.io

它完成了所有测试。