私が持っている gulp-jasmine-phantom
走っていますが、私は ReferenceError: Tictactoe is not defined
。私はいくつかの基本的な間違いをしていると感じています。
私のファイル構造:
gulpfile.js
spec/test.js
source/js/tictactoe.js
コードの簡略化されたバージョン:
ガルプ:
gulp.task("site:js:test", function() {
return gulp.src( "spec/test.js")
.pipe(jasmine())});
test.js:
require("../source/js/tictactoe");
describe("Tictactoe", function() {
var t = new Tictactoe();
it("expects there to be able to add a mark", function() {
t.addMark([0,0], 1);
expect(t.board[0,0]).toBe(1);
});
});
tictactoe.js
function Tictactoe(size) {
this.size = size;
// default variables:
this.EMPTY = "";
this.board = [];
for ( var i = 0; i < this.size; i++ ) {
this.board[i] = [];
for ( var j = 0; j < this.size; j++) {
this.board[i][j] = this.EMPTY;
}
}
}
Tictactoe.prototype.addMark = function(position, player)
{}
私も試みた gulp.src( ["source/js/tictactoe.js", "spec/test.js"] )
テストでは不要です。成功もない。 私も試みた gulp-jasmine
そして gulp-jasmine-browser
。私はそれを動作させることができますか?
事前にありがとう!
回答:
回答№1は0あなたに関連する質問はすでにここで答えられています: Jasmineノードでテストするためのファイルをロードする方法
要するに、モジュールを作成する必要がありますtictactoe関数をエクスポートしてから、Jasmineがアクセスできるローカル変数にそれを必要とします。 Tictactoe関数は現在、必要なJavaScriptファイルのローカルスコープにスコープされています。