From 963b400c413f990511abb95f399c4e410d3bcb18 Mon Sep 17 00:00:00 2001 From: alestiago Date: Tue, 15 Mar 2022 06:57:55 +0000 Subject: [PATCH] refactor: simplified testing for components in tree --- test/game/pinball_game_test.dart | 33 ++++++++++---------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/test/game/pinball_game_test.dart b/test/game/pinball_game_test.dart index a992a471..f79d19d5 100644 --- a/test/game/pinball_game_test.dart +++ b/test/game/pinball_game_test.dart @@ -18,18 +18,13 @@ void main() { // [BallScorePointsCallback] once the following issue is resolved: // https://github.com/flame-engine/flame/issues/1416 group('components', () { - bool Function(Component) componentSelector() => - (component) => component is T; - flameTester.test( 'has three Walls', (game) async { await game.ready(); - final walls = game.children - .where( - (component) => component is Wall && component is! BottomWall, - ) - .toList(); + final walls = game.children.where( + (component) => component is Wall && component is! BottomWall, + ); // TODO(allisonryan0002): expect 3 when launch track is added and // temporary wall is removed. expect(walls.length, 4); @@ -42,10 +37,8 @@ void main() { await game.ready(); expect( - () => game.children.singleWhere( - componentSelector(), - ), - returnsNormally, + game.children.whereType().length, + equals(1), ); }, ); @@ -54,24 +47,18 @@ void main() { 'has only one Plunger', (game) async { await game.ready(); - expect( - () => game.children.singleWhere( - (component) => component is Plunger, - ), - returnsNormally, + game.children.whereType().length, + equals(1), ); }, ); flameTester.test('has only one FlipperGroup', (game) async { await game.ready(); - expect( - () => game.children.singleWhere( - (component) => component is FlipperGroup, - ), - returnsNormally, + game.children.whereType().length, + equals(1), ); }); @@ -79,7 +66,7 @@ void main() { 'has two Baseboards', (game) async { await game.ready(); - final baseboards = game.children.whereType().toList(); + final baseboards = game.children.whereType(); expect(baseboards.length, 2); }, );