testGameWidget method

  1. @isTest
void testGameWidget(
  1. String description, {
  2. WidgetSetupFunction<T>? setUp,
  3. WidgetVerifyFunction<T>? verify,
  4. bool? skip,
  5. Timeout? timeout,
  6. bool? semanticsEnabled,
  7. dynamic tags,
})

Creates a Game specific test case with given description which runs inside the Flutter test environment.

Use setUp closure to prepare your game instance (e.g. add components to it) Use verify closure to make verifications/assertions.

Implementation

@isTest
void testGameWidget(
  String description, {
  WidgetSetupFunction<T>? setUp,
  WidgetVerifyFunction<T>? verify,
  bool? skip,
  Timeout? timeout,
  bool? semanticsEnabled,
  dynamic tags,
}) {
  testWidgets(
    description,
    (tester) async {
      final game = createGame();

      await tester.runAsync(() async {
        final gameWidget =
            createGameWidget?.call(game) ?? GameWidget(game: game);

        final pump = pumpWidget ??
            (GameWidget<T> pumpWidget, WidgetTester tester) =>
                tester.pumpWidget(pumpWidget);

        await pump(gameWidget, tester);
        await tester.pump();

        if (setUp != null) {
          await setUp.call(game, tester);
          await tester.pump();
        }
      });

      if (verify != null) {
        await verify(game, tester);
      }
    },
    skip: skip,
    timeout: timeout,
    semanticsEnabled: semanticsEnabled ?? true,
    tags: tags,
  );
}