I'm using mocha-grunt to be able to run/see my client side tests on the command line. For some reason, it seems that decrementColumn is being called twice when I run my tests on the command line.
I wonder if some sort of phantomJS window scoping problem with beforeEach, because if I copy that block of code ( new Level instantiation) to the top of the decrementColumn test, everything works for both browser and command line.
FUNCTION
decrementColumn: function( columnPosition ){
--this.columns[ 0 ]
},
TEST
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 )
})
})
})
GRUNTFILE
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>