【发布时间】:2012-09-20 19:21:09
【问题描述】:
我只是在使用 RequireJS 和 Jasmine 的单元测试策略中寻找依赖注入。我真的很喜欢testr 背后的想法,并且我尝试按照 github 中的示例设置 testr,但我不知道出了什么问题。我总是得到错误
错误:模块尚未加载:今天
当 testr 尝试加载要测试的模块时。
这里有一些上下文..
index.html ..
<script data-main="config" src="../../assets/js/libs/require.js"></script>
<script src="vendor/testr.js"></script>
config.js ..
require.config({
// Initialize specs.
deps:["main"],
...
...
});
main.js ..
require([
// Load the example spec, replace this and add your own spec
"spec/today"
], function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.execute();
});
规范\today.js ..
describe('Today print', function() {
var date = {}, today;
beforeEach(function() {
date.today = new Date(2012, 3, 30);
today = testr('today', {'util/date': date}); //Here is where the error is thrown
});
it('is user-friendly', function() {
expect(today.getDateString()).toBe('Today is Monday, 30th April, 2012');
});
});
today.js ..
define(['string', 'util/date'], function(string, date) {
return {
getDateString: function() {
return string.format('Today is %d', date.today);
}
}
});
有没有人遇到过同样的问题? .我正在使用 RequireJS 2.0.6
谢谢。
【问题讨论】:
标签: unit-testing dependency-injection requirejs jasmine