CoffeeScript 代码单元测试 AngularJS - Jasmine - Karma
CoffeeScript Code UnitTest AngularJS - Jasmine - Karma
我正在尝试为使用 CoffeeScript 编写的 Ionic 项目的控制器和服务编写单元测试。我选择使用 Karma 和 Jasmine。问题是它不解释 coffeeScript。这就是为什么我使用这个插件 karma-coffee-preprocessor 以便它成为可能。不知道我做的对不对
我用命令安装了插件;
npm install --save-dev karma-coffee-preprocessor
然后我配置我的测试配置文件如下:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'../bower_components/angular/angular.js',
'../bower_components/angular-ui-router/release/angular-ui-router.js',
'../bower_components/angular-mocks/angular-mocks.js',
'../src/scripts/**/*.coffee',
'unit-tests/**/*.js'
],
exclude: [
],
preprocessors: {
'../src/scripts/**/*.coffee': ['coffee']
},
coffeePreprocessor: {
options: {
bare: true,
sourceMap: false
},
transformPath: function(path) {
return path.replace(/\.coffee$/, '.js')
}
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: false,
concurrency: Infinity
})
}
但是当我尝试开始我的测试时出现了这个错误:
Can not load "coffee", it is not registered!
Perhaps you are missing some plugin?
/opt/node/lib/node_modules/karma/node_modules/di/lib/injector.js:9
throw error('No provider for "' + name + '"!');
^
Error: No provider for "framework:jasmine"! (Resolving: framework:jasmine)
at error (/opt/node/lib/node_modules/karma/node_modules/di/lib/injector.js:22:12)
at Object.parent.get (/opt/node/lib/node_modules/karma/node_modules/di/lib/injector.js:9:13)
at get (/opt/node/lib/node_modules/karma/node_modules/di/lib/injector.js:54:19)
at /opt/node/lib/node_modules/karma/lib/server.js:138:20
at Array.forEach (native)
at Server._start (/opt/node/lib/node_modules/karma/lib/server.js:137:21)
at invoke (/opt/node/lib/node_modules/karma/node_modules/di/lib/injector.js:75:15)
at Server.start (/opt/node/lib/node_modules/karma/lib/server.js:102:18)
at Object.exports.run (/opt/node/lib/node_modules/karma/lib/cli.js:243:26)
at Object.<anonymous> (/opt/node/lib/node_modules/karma/bin/karma:3:23)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:146:18)
谁能帮帮我?
我在进行这些单元测试时遇到了麻烦,而且我不知道我做事的方式是否正确。
首先您需要通过 npm 安装 jasmine 框架并将其添加到 karma 配置文件中的框架集合中:
$ npm install karma-jasmine --save-dev
然后添加:
frameworks: ['jasmine']
到 karma 配置文件。
我正在尝试为使用 CoffeeScript 编写的 Ionic 项目的控制器和服务编写单元测试。我选择使用 Karma 和 Jasmine。问题是它不解释 coffeeScript。这就是为什么我使用这个插件 karma-coffee-preprocessor 以便它成为可能。不知道我做的对不对
我用命令安装了插件;
npm install --save-dev karma-coffee-preprocessor
然后我配置我的测试配置文件如下:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'../bower_components/angular/angular.js',
'../bower_components/angular-ui-router/release/angular-ui-router.js',
'../bower_components/angular-mocks/angular-mocks.js',
'../src/scripts/**/*.coffee',
'unit-tests/**/*.js'
],
exclude: [
],
preprocessors: {
'../src/scripts/**/*.coffee': ['coffee']
},
coffeePreprocessor: {
options: {
bare: true,
sourceMap: false
},
transformPath: function(path) {
return path.replace(/\.coffee$/, '.js')
}
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: false,
concurrency: Infinity
})
}
但是当我尝试开始我的测试时出现了这个错误:
Can not load "coffee", it is not registered!
Perhaps you are missing some plugin?
/opt/node/lib/node_modules/karma/node_modules/di/lib/injector.js:9
throw error('No provider for "' + name + '"!');
^
Error: No provider for "framework:jasmine"! (Resolving: framework:jasmine)
at error (/opt/node/lib/node_modules/karma/node_modules/di/lib/injector.js:22:12)
at Object.parent.get (/opt/node/lib/node_modules/karma/node_modules/di/lib/injector.js:9:13)
at get (/opt/node/lib/node_modules/karma/node_modules/di/lib/injector.js:54:19)
at /opt/node/lib/node_modules/karma/lib/server.js:138:20
at Array.forEach (native)
at Server._start (/opt/node/lib/node_modules/karma/lib/server.js:137:21)
at invoke (/opt/node/lib/node_modules/karma/node_modules/di/lib/injector.js:75:15)
at Server.start (/opt/node/lib/node_modules/karma/lib/server.js:102:18)
at Object.exports.run (/opt/node/lib/node_modules/karma/lib/cli.js:243:26)
at Object.<anonymous> (/opt/node/lib/node_modules/karma/bin/karma:3:23)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:146:18)
谁能帮帮我? 我在进行这些单元测试时遇到了麻烦,而且我不知道我做事的方式是否正确。
首先您需要通过 npm 安装 jasmine 框架并将其添加到 karma 配置文件中的框架集合中:
$ npm install karma-jasmine --save-dev
然后添加:
frameworks: ['jasmine']
到 karma 配置文件。