-
-
Save Katamori/4108a7644ac5cc57df5748e1ea025849 to your computer and use it in GitHub Desktop.
Bootstrapping a Phaser game to begin unit testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var game; | |
function createGame() { | |
game = new MyGame.Game(); | |
game.state.onStateChange.add(function (state) { | |
if (state === 'menu') { | |
runTests(); // wait for boot + preload to complete before running tests | |
} | |
}, this); | |
game.play(); // init's game and sets the initial Phaser.State | |
} | |
function runTests() { | |
if (window.mochaPhantomJS) { | |
mochaPhantomJS.run(); | |
} | |
else { | |
mocha.run(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="utf-8"> | |
<link rel="stylesheet" href="../node_modules/mocha/mocha.css"/> | |
<title>Phaser Mocha Tests</title> | |
<style> | |
#canvasContainer { | |
display: none; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="mocha"></div> | |
<script src="../node_modules/mocha/mocha.js"></script> | |
<script src="../node_modules/chai/chai.js"></script> | |
<script> | |
mocha.ui('bdd'); | |
mocha.reporter('html'); | |
expect = chai.expect; | |
assert = chai.assert; | |
</script> | |
<script src="../dist/game.js"></script> | |
<script src="../test/bootstrap.js"></script> | |
<script src="../test/entities/player.test.js"></script> | |
<script> | |
createGame(); | |
</script> | |
<div id="canvasContainer"></div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Player', function() { | |
describe('#constructor()', function () { | |
it('should start off-screen', function () { | |
var p = new MyGame.Entity.Player(game); | |
expect(p.x).to.equal(game.width + p.width); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment