Currently, if one is testing with testGameWidget
in order to test the subject within verify
it requires the developer to traverse the game tree and find the subject they are interested in.
flame.testGameWidget('example test',
setUp: (game, tester) async {
final fooComponent = FooComponent();
final booComponent = BooComponent();
await booComponent.add(fooComponent);
await game.add(booComponent);
},
verify: (game, tester) {
final fooComponent = game.descendants().whereType<FooComponent>.first;
// The above is error prone, depends on how the given game tree is structured.
expect(fooComponent.something, isTrue);
},
);
Something as below would be useful. Including a build
parameter and updating the signature to:
void testGameWidget<G extends Game, S>(
String description, {
Future<void> Function(G game, WidgetTester tester)? setUp,
required Future<S> Function(G game, WidgetTester tester) build,
Future<void> Function(G game, S subject, WidgetTester tester)? verify,
})
or
void testGameWidget<G extends Game, S>(
String description, {
Future<void> Function(G game, WidgetTester tester)? setUp,
required Future<S> Function(G game, WidgetTester tester) build,
Future<void> Function(S subject, WidgetTester tester)? verify,
})
Although with the latter signature I think it would be challenging to test/verify something that requires both the game and the subject. The subject could be the game and then we would have to traverse (same problem).
Another proposal could be with an act
parameter:
void testGameWidget<G extends Game, S>(
String description, {
required Future<S> Function(G game, WidgetTester tester)? setUp,
Future<void> Function(G game, S subject, WidgetTester tester) act,
Future<void> Function(G game, S subject, WidgetTester tester)? verify,
})
Note: the above snippets are a quick proposal, it is open to change. I didn't use typedef for readability.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too