我一直在尝试使用requirejs和js-test-driver,我无法让它发挥作用。
我在root上有这样的最小配置:
server: http://localhost:9876
load:
- src/main/resources/web/resources/vendor/requirejs/require.js
test:
- src/test/js/*.js
A" src / main / js / greeter.js" file定义了一个愚蠢的模块:
define(function(require) {
myapp = {};
myapp.Greeter = function() {
};
myapp.Greeter.prototype.greet = function(name) {
return "Hello " + name + "!";
};
return myapp;
});
我试图让#require /#34; src / test / js / greeterTest.js" :
GreeterTest = TestCase("GreeterTest");
require.configure({ ???? });
require([ "src/main/js/greeter" ], function(myapp) {
GreeterTest.prototype.testGreet = function() {
var greeter = new myapp.Greeter();
assertEquals("Hello World!", greeter.greet("World"));
};
});
每当我运行它时,我都会收到错误,因为在创建Greeter时未定义myapp。
在这种情况下,我可以配置一种方法吗?我试过了:
还有什么我应该尝试的吗?
由于
答案 0 :(得分:1)
事实证明这是可能的,但记录不清:
这样可行:
server: http://localhost:9876
load:
- src/main/resources/web/resources/vendor/requirejs/require.js
test:
- src/test/js/*.js
serve:
- src/main/js/*.js
必须像这样配置requirejs:
require({
baseUrl : "/test/src/main/js"
}, [ "greeter" ], function(myapp) {
GreeterTest = TestCase("GreeterTest");
GreeterTest.prototype.testGreet = function() {
var greeter = new myapp.Greeter();
assertEquals("Hello World!", greeter.greet("World"));
};
});
注意: