我有麻煩得到一個簡單的業力測試運行。我有以下的代碼結構:karma無法加載由requirejs注入的文件
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}
];
在我的控制器。 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);
});
});
});
});
0123來測試這個功能
問題是我的瀏覽器無法加載controllers.js
文件eventhough我建立了我的主要測試文件的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
。這不是正確的道路嗎?