连接茉莉规范文件到我的JS文件

Connecting Jasmine spec file to my JS file

本文关键字:文件 我的 JS 范文件 连接      更新时间:2023-09-26

我正在尝试为我的井字游戏编写测试。错误提示'ReferenceError: CountClick is not defined', 'ReferenceError: Board is not defined'

我猜TicTacToeSpec文件没有在我的TicTacToe.js文件中读取。我如何让他们彼此认识?

规范/javascript/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();
 }

按照https://github.com/pivotal/jasmine/tree/master/dist的Pivotal文件结构将lib文件添加到您自己的项目中,并使用类似于他们自己的索引页。

TicTacToe.js和tictactoepec .js都必须包含在HTML测试工具中。你发布的代码不包括TicTacToe.js。你的脚本应该包括:

<script src="path/to/TicTacToe.js"></script>
<script src="spec/javascripts/TicTacToeSpec.js"></script>