testWithGame<T extends FlameGame<World> > function
- @isTest
- String testName,
- CreateFunction<
T> create, - AsyncGameFunction<
T> testBody, { - Timeout? timeout,
- dynamic tags,
- dynamic skip,
- Map<
String, dynamic> ? onPlatform, - int? retry,
Utility function for writing tests that require a custom game instance.
This function create
s the game instance, initializes it, then passes it
to the user-provided testBody
, and in the end disposes of the game object.
Example of usage:
testWithGame<MyGame>(
'MyComponent can be added to MyGame',
() => MyGame(mySecret: 3781),
(MyGame game) async {
final component = MyComponent()..addToParent(game);
await game.ready();
expect(component.isMounted, true);
},
);
Implementation
@isTest
Future<void> testWithGame<T extends FlameGame>(
String testName,
CreateFunction<T> create,
AsyncGameFunction<T> testBody, {
Timeout? timeout,
dynamic tags,
dynamic skip,
Map<String, dynamic>? onPlatform,
int? retry,
}) async {
test(
testName,
() async {
final game = await initializeGame<T>(create);
await testBody(game);
game.onRemove();
},
timeout: timeout,
tags: tags,
skip: skip,
onPlatform: onPlatform,
retry: retry,
);
}