Skip to content

Instantly share code, notes, and snippets.

@idmontie
Created September 14, 2015 22:46
Show Gist options
  • Save idmontie/0c007ece2698306acdf4 to your computer and use it in GitHub Desktop.
Save idmontie/0c007ece2698306acdf4 to your computer and use it in GitHub Desktop.
Jasmine Phaser Matcher
this.game.stage.children <-- array of objects
this.game.stage.children[0] <-- object with children as array of object
this.game.stage.children[0].children <--- array of objects
expect( this.game.stage ).has( Phaser.TEXT ).withText( 'Take That, Robot!' );
expect( this.game.stage ).has( Phaser.BUTTON ).has( 'text' ).withText( 'Play' );
var phaserMatcher = {
has : function ( type ) {
return {
compare: function pasherMatcherComparitor( gameObject ) {
var result = { pass: false };
// Check if we are chaining
if ( gameObject.pass === false ) {
return gameObject;
}
if ( gameObject.type && gameObject.type == type ) {
result.pass = true;
} else if ( gameObject.children && gameObject.children.length > 0 ) {
var recursiveResults = [];
// Call self with each child
for ( var i = 0; o < gameObject.children.length; i++ ) {
var recursiveResult = pasherMatcherComparitor( gameObject.children[i];
if ( recursiveResult.pass ) {
recursiveResults.concat( recursiveResult.children );
}
}
if ( recursiveResults.length > 0 ) {
result.pass = true;
result.children = recursiveResults;
} else {
result.pass = false;
result.message = 'No child of type ' + type + ' found';
}
} else {
result.pass = false;
result.message = 'No child of type ' + type + ' found';
}
return result;
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment