我试图为我的井字游戏编写测试。错误说' ReferenceError:CountClick未定义',' ReferenceError:Board未定义&#39 ;
我的猜测是我的TicTacToe.js文件中没有读取TicTacToeSpec文件。我如何让彼此知道?
spec / javascripts / TicTacToeSpec.js
describe('Count clicks', function() {
it('adds 1 to counter when clicked', function() {
counter = 0;
CountClick();
expect(counter).toEqual(1);
});
});
/index.html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type='text/javascript'></script>
<script src="TicTacToe.js"></script>
<script src="spec/javascripts/TicTacToeSpec.js"></script>
/ Gemfile中
gem 'jquery-rails', '~> 2.0.0'
gem 'jasmine'
gem 'jasminerice'
/TicTacToe.js
function CountClick() {
counter++;
};
function Board() {
this.initialBoard();
this.newBoard();
game.firstMove();
}
答案 0 :(得分:0)
按照Pivotal文件结构关注https://github.com/pivotal/jasmine/tree/master/dist,将lib文件添加到您自己的项目中,索引页面与自己的索引页面类似。
答案 1 :(得分:0)
TicTacToe.js和TicTacToeSpec.js都必须包含在HTML测试工具中。您发布的代码不包括TicTacToe.js。您的脚本包括:
<script src="path/to/TicTacToe.js"></script>
<script src="spec/javascripts/TicTacToeSpec.js"></script>