Skip to content

Instantly share code, notes, and snippets.

@Katamori
Forked from cloakedninjas/bootstrap.js
Created February 16, 2020 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Katamori/4108a7644ac5cc57df5748e1ea025849 to your computer and use it in GitHub Desktop.
Save Katamori/4108a7644ac5cc57df5748e1ea025849 to your computer and use it in GitHub Desktop.
Bootstrapping a Phaser game to begin unit testing
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();
}
}
<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>
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