Skip to content

Commit

Permalink
test: Always clean up after failed test (#3307)
Browse files Browse the repository at this point in the history
When running several `testWithGame` (or `testWithFlameGame`) tests after
one another, if one test failed with a thrown error (e.g. failed
`expect()`), the following ones would fail as well with failed assertion
`Component.staticGameInstance == null`. This is because
`game.onRemove()` didn't get to run after the thrown error.

This polluted the output and made it hard to understand which test
actually failed and which didn't. It was also confusing to new users.
  • Loading branch information
filiph authored Sep 19, 2024
1 parent 026bf41 commit 0b1e184
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/flame_test/lib/src/test_flame_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ Future<void> testWithGame<T extends FlameGame>(
testName,
() async {
final game = await initializeGame<T>(create);
await testBody(game);

game.onRemove();
try {
await testBody(game);
} finally {
game.onRemove();
}
},
timeout: timeout,
tags: tags,
Expand Down

0 comments on commit 0b1e184

Please sign in to comment.