最初に言いたいのは、私は RequireJS の初心者であり、Jasmine の初心者です。
SpecRunner に問題があり、JS が必要です。私は Uzi Kilon と Ben Nadel のチュートリアルに従っています (他のいくつかのチュートリアルと一緒に)。
テストでエラーがスローされた場合 (特に型エラーが考えられます)、spec runner html が表示されるようです。これは、javascript に問題があることを示しています。ただし、これらのエラーを修正すると、HTML が表示されなくなります。 テストランナーをまったく表示できません。この問題の原因となる私のコードの問題を誰かが見つけることができますか?
ここに私のディレクトリ構造があります:
Root
|-> lib
|-> jasmine
|-> lib (contains all of the jasmine lib)
|-> spec
|-> src
|-> jquery (jquery js file)
|-> require (require js file)
index.html (spec runner) specRunner.js
SpecRunner (インデックス) HTMLは次のとおりです。
<!doctype html>
<html lang="en">
<head>
<title>Javascript Tests</title>
<link rel="stylesheet" href="lib/jasmine/lib/jasmine.css">
<script src="lib/jasmine/lib/jasmine.js"></script>
<script src="lib/jasmine/lib/jasmine-html.js"></script>
<script src="lib/jquery/jquery.js"></script>
<script data-main="specRunner" src="lib/require/require.js"></script>
<script>
require({ paths: { spec: "lib/jasmine/spec" } }, [
// Pull in all your modules containing unit tests here.
"spec/notepadSpec"
], function () {
jasmine.getEnv().addReporter(new jasmine.HtmlReporter());
jasmine.getEnv().execute();
});
</script>
</head>
<body>
</body>
</html>
これがspecRunner.js(構成)です
require.config({
urlArgs: 'cb=' + Math.random(),
paths: {
jquery: 'lib/jquery',
jasmine: 'lib/jasmine/lib/jasmine',
'jasmine-html': 'lib/jasmine/lib/jasmine-html',
spec: 'lib/jasmine/spec/'
},
shim: {
jasmine: {
exports: 'jasmine'
},
'jasmine-html': {
deps: ['jasmine'],
exports: 'jasmine'
}
}
});
ここに仕様があります:
require(["../lib/jasmine/src/notepad"], function (notepad) {
describe("returns titles", function() {
expect(notepad.noteTitles()).toEqual("");
});
});
メモ帳のソース:
define(['lib/jasmine/src/note'], function (note) {
var notes = [
new note('pick up the kids', 'dont forget to pick up the kids'),
new note('get milk', 'we need two gallons of milk')
];
return {
noteTitles: function () {
var val;
for (var i = 0, ii = notes.length; i < ii; i++) {
//alert(notes[i].title);
val += notes[i].title + ' ';
}
return val;
}
};
});
そしてメモのソース (JIC):
define(function (){
var note = function(title, content) {
this.title = title;
this.content = content;
};
return note;
});
アプリに関する限り、パスが正しいことを確認しました。これが機能するようになったら、そのパスを構成して遊ぶことができるので、それほど厄介ではありません。