我对 RequireJS 很陌生,并且在将 QUnit 写入具有使用 requireJS 动态加载模块的逻辑的源代码时遇到了麻烦。
以下是源代码:factory/Factory.js *
getPage: function (callback) {
//doSomething here
require(['page/something'], function() {
callback();
})
}
运行 QUnit 时永远不会加载模块“page/something”,并且永远不会调用回调。我在这里有什么遗漏吗?感谢您的回复。
* *QUnit 工厂/FactoryTests.js*
define(['underscore', 'factory/Factory'],
function (_, Factory) {
module("Factory", {
setup:function () {
},
teardown:function () {
}
});
test("GetPage", function () {
var isCallbackInvoked = false;
var mockCallback = function () {
isCallbackInvoked = true;
}
Factory.getPage(mockCallback);
ok(isCallbackInvoked);
});
});
* test-require-config.js **
require.config({
baseUrl: "../../resources/js",
paths:{
jquery:'../jquery-1.8.2',
jquery_star_rating : '../jquery/jquery.rating',
underscore:'..underscore-1.4.1',
backbone:'../backbone-0.9.2',
jquery_star_rating : '../jquery.rating',
text : '../require-text-2.0.3',
sinon: '../../../../sinon',
},
shim:{
underscore:{
exports:'_'
},
backbone:{
deps:["jquery", "underscore"],
exports:"Backbone"
}
jquery_star_rating : {
deps : ['jquery']
}
}
});
var dependencies = [
'jquery',
'jquery_star_rating',
'underscore',
'backbone',
'sinon',
];
require(dependencies, function () {
require(['../../../../test/js/testsuite'], function(suite){
})
});
测试套件.js
function () {
QUnit.config.autostart = false;
var testModules = [
"factory/FactoryTests.js"
];
require(testModules, QUnit.start);
}());
谢谢!!