我是Unit Testing
的新手,所以我今天才知道Jasmine
和Karma
。
我安装了Karma:
npm init
npm install karma --save-dev
npm install -g karma-cli
npm install karma-jasmine --save-dev
npm install karma-chrome-launcher --save-dev
karma init
然而,当我尝试启动karma start karma.conf.js
时,它会抛出一个错误:
Error: Cannot find module 'jasmine-core'
at Function.Module._resolveFilename (module.js:338:15)
at Function.require.resolve (module.js:389:19)
at initJasmine (/Users/appfoundry/Projects/Unit Testing/node_modules/karma-jasmine/lib/index.js:8:42)
at Array.invoke (/Users/appfoundry/Projects/Unit Testing/node_modules/di/lib/injector.js:75:15)
at get (/Users/appfoundry/Projects/Unit Testing/node_modules/di/lib/injector.js:48:43)
at /Users/appfoundry/Projects/Unit Testing/node_modules/karma/lib/server.js:137:20
at Array.forEach (native)
at Server._start (/Users/appfoundry/Projects/Unit Testing/node_modules/karma/lib/server.js:136:21)
at invoke (/Users/appfoundry/Projects/Unit Testing/node_modules/di/lib/injector.js:75:15)
at Server.start (/Users/appfoundry/Projects/Unit Testing/node_modules/karma/lib/server.js:101:18)
at Object.exports.run (/Users/appfoundry/Projects/Unit Testing/node_modules/karma/lib/cli.js:231:26)
at requireCliAndRun (/usr/local/lib/node_modules/karma-cli/bin/karma:44:16)
at /usr/local/lib/node_modules/karma-cli/bin/karma:54:12
at /usr/local/lib/node_modules/karma-cli/node_modules/resolve/lib/async.js:44:21
at ondir (/usr/local/lib/node_modules/karma-cli/node_modules/resolve/lib/async.js:187:31)
at /usr/local/lib/node_modules/karma-cli/node_modules/resolve/lib/async.js:153:39
我试图在全球范围内安装核心:
npm install -g jasmine-core
但这并没有解决它。
当我尝试安装npm install karma-jasmine
时,我收到错误消息:
karma-jasmine@0.3.6 requires a peer of jasmine-core@* but none was installed.
答案 0 :(得分:8)
https://github.com/karma-runner/karma-jasmine
注意:由于karma-jasmine 0.3.0茉莉花库不再与karma-jasmine捆绑在一起,你必须自己安装它。您可以通过以下方式完成:
npm install jasmine-core --save-dev
$ npm install jasmine-core --save-dev
$ npm install karma-jasmine --save-dev
答案 1 :(得分:1)
问题是Karma正在全球范围内运行。
我的解决方案(至少对我来说最简单,最轻松)是使用npm脚本karma start
命令包装test
命令,以便在本地环境中运行任何命令。
在 package.json 中,在"test": "karma start"
中添加"scripts": {}
。
"scripts": {
"test": "karma start",
[...]
},