【发布时间】:2013-07-03 19:32:57
【问题描述】:
我无法运行一个简单的业力测试。我有以下代码结构:
js/
|-- tests.js
|-- karma.config.js
|-- app/
|-- controllers.js
|-- tests/
|-- unit/
|-- loginSpec.js
|-- vendor/
|-- jquery.js
我正在关注http://karma-runner.github.io/0.8/plus/RequireJS.html 的文档,并将我的配置设置如下(减去不重要的部分):
// base path, that will be used to resolve files and exclude
basePath = '';
// list of files / patterns to load in the browser
files = [
JASMINE,
JASMINE_ADAPTER,
REQUIRE,
REQUIRE_ADAPTER,
'tests.js',
{pattern: 'tests/unit/*.js', included: false}
];
在我的 controllers.js 中,我定义了一个名为 LoginCtrl 的函数,我想在 loginSpec.js 中测试这个函数
define(['controllers'],function(controllers) {
describe('Login controllers', function() {
describe('LoginCtrl', function(){
it('should return 1', function() {
var scope = {},
ctrl = new LoginCtrl(scope);
expect(1).toBe(1);
});
});
});
});
问题是我的浏览器无法加载controllers.js 文件,尽管我已将我的主测试文件的requirejs 配置(tests.js)设置如下:
var tests = Object.keys(window.__karma__.files).filter(function (file) {
return /Spec\.js$/.test(file);
});
requirejs.config({
baseUrl: '/base/app',
paths: {
jquery: 'vendor/jquery',
},
deps: tests,
callback: window.__karma__.start
});
浏览器确实会在http://localhost:9876/base/app/controllers.js 处查找文件。这不是正确的道路吗?
【问题讨论】: