Skip to content

Commit

Permalink
test: Add test for two subsequent state changes to flame_multi_bloc_p…
Browse files Browse the repository at this point in the history
…rovider_test.dart (#2381)

This is a cleanup identified on this issue: #2308
Using an amazing unused-code tooling
Now, since Flame is a public API, unused code might not be trivial - it might just mean untested code.

In this case, it is a test file, so there should definitely be no unused code.
However analyzing the unused code revealed to me some intent of testing multiple subsequent state changes (dead -> raise from dead).
I believe such test was missing entirely, so I added it. I think it holds value, but lmk if you disagree I can just delete the test and the method.
  • Loading branch information
luanpotter authored and st-pasha committed Mar 2, 2023
1 parent 10aa5e9 commit 775de23
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/flame_bloc/test/src/flame_multi_bloc_provider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,34 @@ void main() {
expect(player.lastState, equals(PlayerState.sad));
expect(inventory.lastState, equals(InventoryState.bow));
});

testWithFlameGame(
'can listen to multiple subsequent state changes',
(game) async {
final playerCubit = PlayerCubit();
late PlayerListener player;

final provider = FlameMultiBlocProvider(
providers: [
FlameBlocProvider<PlayerCubit, PlayerState>.value(
value: playerCubit,
),
],
children: [
player = PlayerListener(),
],
);
await game.ensureAdd(provider);

playerCubit.kill();
await Future<void>.microtask(() {});
expect(player.lastState, equals(PlayerState.dead));

playerCubit.riseFromTheDead();
await Future<void>.microtask(() {});
expect(player.lastState, equals(PlayerState.alive));
},
);
});
});
}

0 comments on commit 775de23

Please sign in to comment.