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();
});
spec\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');
});
});
今日.js ..
define(['string', 'util/date'], function(string, date) {
return {
getDateString: function() {
return string.format('Today is %d', date.today);
}
}
});
同じように悩んだ人はいませんか?. 私はRequireJS 2.0.6を使用しています
ありがとう。