testWithFlameGame function
Utility function for writing tests that require a FlameGame
instance.
This function creates a FlameGame
object, properly initializes it, then
passes on to the user-provided testBody
, and in the end disposes of the
game object.
Example of usage:
testWithFlameGame(
'MyComponent can be added to a game',
(game) async {
final component = MyComponent()..addToParent(game);
await game.ready();
expect(component.isMounted, true);
},
);
The game
instance supplied by this function to your testBody
is a
standard FlameGame
. If you want to have any other game instance, use the
testWithGame function.
Implementation
@isTest
Future<void> testWithFlameGame(
String testName,
AsyncGameFunction<FlameGame> testBody, {
Timeout? timeout,
dynamic tags,
dynamic skip,
Map<String, dynamic>? onPlatform,
int? retry,
}) {
return testWithGame<FlameGame>(
testName,
FlameGame.new,
testBody,
timeout: timeout,
tags: tags,
skip: skip,
onPlatform: onPlatform,
retry: retry,
);
}