我正在使用 mocha-grunt 能够在命令行上运行/查看我的客户端测试。出于某种原因,当我在命令行上运行测试时,似乎调用了 decrementColumn 两次。
我想知道 beforeEach 是否存在某种 phantomJS 窗口范围问题,因为如果我将该代码块(新级别实例化)复制到 decrementColumn 测试的顶部,则一切都适用于浏览器和命令行。
功能
decrementColumn: function( columnPosition ){
--this.columns[ 0 ]
},
测试
describe( 'Level', function(){
beforeEach( function(){
level = new Level( [ 2, 3, 5 ] )
})
describe( '#decrementColumn()', function(){
it( 'should reduce column by one', function(){
level.decrementColumn( 1 )
expect ( level.columns[ 0 ] ).to.equal( 1 )
})
})
})
咕噜文件
module.exports = function( grunt ){
grunt.initConfig({
pkg: grunt.file.readJSON( 'package.json' ),
mocha: {
all: {
src: [ 'test/runner.html' ],
},
options: {
reporter: 'Spec',
run: true
}
}
});
grunt.loadNpmTasks( 'grunt-mocha' )
grunt.registerTask( 'default', [ 'mocha' ] )
};
SPECRUNNER
<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link rel="stylesheet" href="../lib/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<!-- mocha dependencies -->
<script type="text/javascript" src="../lib/jquery.min.js"></script>
<script type="text/javascript" src="../lib/expect.js"></script>
<script type="text/javascript" src="../lib/mocha.js"></script>
<script type="text/javascript" src="../lib/chai.js"></script>
<!-- application files -->
<script type="text/javascript" src='../client/view.js'></script>
<script type="text/javascript" src='../client/logic.js'></script>
<script type="text/javascript" src='../client/level.js'></script>
<script type="text/javascript" src='../client/game.js'></script>
<script type="text/javascript" src='../client/init.js'></script>
<!-- configure mocha && chai -->
<script>
mocha.setup( 'bdd' )
expect = chai.expect
</script>
<!-- test files -->
<script type="text/javascript" src='level-spec.js'></script>
<script>
mocha.globals(['jQuery']);
mocha.run();
</script>
</body>
</html>