试图让karma启动并运行,得到以下错误消息,业力似乎没有看到js文件,不知道如何纠正它,并且随后没有看到角度模块。我也看过文档和业力文档,但没有找到解决方案。
想法?
我的设置基于honeybadger.io https://www.honeybadger.io/blog/2013/12/11/beginners-guide-to-angular-js-rails
^C[jd@mbp ~/Dropbox/angular_projects/lookingtolunch (master *)]$ karma start spec/javascripts/lunch.conf.js
INFO [karma]: Karma v0.10.9 server started at http://localhost:9876/
WARN [watcher]: Pattern "/Users/jd/Dropbox/angular_projects/lookingtolunch/app/assets/javascripts/angular.js" does not match any file.
WARN [watcher]: Pattern "/Users/jd/Dropbox/angular_projects/lookingtolunch/app/assets/javascripts/angular-mocks.js" does not match any file.
WARN [watcher]: Pattern "/Users/jd/Dropbox/angular_projects/lookingtolunch/app/assets/javascripts/angular-route.js" does not match any file.
WARN [watcher]: Pattern "/Users/jd/Dropbox/angular_projects/lookingtolunch/app/assets/javascripts/angular/*" does not match any file.
WARN [watcher]: Pattern "/Users/jd/Dropbox/angular_projects/lookingtolunch/app/assets/javascripts/app.js.coffee" does not match any file.
WARN [watcher]: Pattern "/Users/jd/Dropbox/angular_projects/lookingtolunch/app/assets/javascripts/controllers.js.coffee" does not match any file.
WARN [watcher]: Pattern "/Users/jd/Dropbox/angular_projects/lookingtolunch/app/assets/javascripts/services.js.coffee" does not match any file.
INFO [Chrome 32.0.1700 (Mac OS X 10.9.1)]: Connected on socket LuVlKBCaXZHpAuDSxZbt
Chrome 32.0.1700 (Mac OS X 10.9.1) Lunch controller encountered a declaration exception FAILED
ReferenceError: module is not defined
at null.<anonymous> (/Users/jd/Dropbox/angular_projects/lookingtolunch/spec/javascripts/lunch_controller_spec.js.js:2:14)
at /Users/jd/Dropbox/angular_projects/lookingtolunch/spec/javascripts/lunch_controller_spec.js.js:1:1
Chrome 32.0.1700 (Mac OS X 10.9.1): Executed 1 of 1 (1 FAILED) ERROR (3.955 secs / 0.779 secs)
我的app.js.coffee
Lunch = angular.module('Lunch', ['ngRoute','Lunch.controllers', 'Lunch.services'])
Lunch.config([ '$routeProvider', ($routeProvider) ->
$routeProvider.when("/", { templateUrl: "/ngviews/lunch.html", controller: "LunchCtrl" } )
])
我的spec文件看起来像
describe "Lunch controller", ->
beforeEach module("Lunch")
describe "LunchCtrl", ->
it "should set images to a populated array", inject(($controller) ->
scope = {}
ctrl = $controller("LunchCtrl",
$scope: scope
)
expect(scope.luncher.length).toBe 4
)
和我的spec / javascripts / lunch.conf.js
module.exports = function (config) {
config.set({
basePath: '../..',
frameworks: ['jasmine'],
autoWatch: true,
preprocessors: {
'**/*.coffee': 'coffee'
},
files: [
'app/assets/javascripts/angular.js',
'app/assets/javascripts/angular-mocks.js',
'app/assets/javascripts/angular-route.js',
'app/assets/javascripts/angular/*',
'app/assets/javascripts/app.js.coffee',
'app/assets/javascripts/controllers.js.coffee',
'app/assets/javascripts/services.js.coffee',
'spec/javascripts/*_spec.js.coffee'
]
});
};
答案 0 :(得分:0)
我最终复制了一个我在互联网上找到的conf文件,虽然与zurb基金会的js存在某种冲突,但这似乎有效。
module.exports = function (config) {
config.set({
basePath: '../..',
frameworks: ['jasmine'],
autoWatch: true,
preprocessors: {
'**/*.coffee': 'coffee'
},
files: [
'http://localhost:3000/assets/application.js',
'spec/javascripts/lunch_controller_spec.js.coffee',
{
pattern: 'app/assets/javascripts/*.{js,coffee}',
watched: true,
included: false,
served: false
}
]
});
};
答案 1 :(得分:0)
由于默认的咖啡预处理器命名约定,因此Karma无法找到这些文件。
预处理器期望找到.coffee文件(即app.coffee)并在处理(app.js)后提供.js文件。您的文件名为.js.coffee(看起来您正在使用rails),因此它们在file.js.js中提供。 如果您试一试并查找'localhost:9876 / base / app / assets / javascripts / angular.js.js',您将在那里找到该文件。
解决方案: 按照文档(https://github.com/karma-runner/karma-coffee-preprocessor),您可以将其添加到您的karma.conf.js:
coffeePreprocessor: {
// options passed to the coffee compiler
options: {
bare: false,
sourceMap: true
},
// transforming the filenames
transformPath: function(path) {
return path.replace(/\.js.coffee$/, '.js');
}
},
并在预期位置找到文件(因此业力也将如此): 本地主机:9876 /碱/应用程序/资产/ Javascript角/ angular.js