Skip to content

Commit a5cc6c8

Browse files
committed
Test mounted guard when updating state asynchronously from a new widget
1 parent 2ce59f0 commit a5cc6c8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

packages/google_maps_flutter/google_maps_flutter/test/google_map_test.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,4 +579,35 @@ void main() {
579579

580580
expect(map.mapConfiguration.style, '');
581581
});
582+
583+
testWidgets('Update state from widget only when mounted',
584+
(WidgetTester tester) async {
585+
await tester.pumpWidget(
586+
const Directionality(
587+
textDirection: TextDirection.ltr,
588+
child: GoogleMap(
589+
initialCameraPosition: CameraPosition(target: LatLng(10.0, 15.0)),
590+
),
591+
),
592+
);
593+
594+
final State<StatefulWidget> googleMapState =
595+
tester.state(find.byType(GoogleMap));
596+
597+
await tester.pumpWidget(Container());
598+
599+
// ignore:invalid_use_of_protected_member
600+
googleMapState.didUpdateWidget(
601+
GoogleMap(
602+
initialCameraPosition: const CameraPosition(target: LatLng(10.0, 15.0)),
603+
circles: <Circle>{const Circle(circleId: CircleId('circle'))},
604+
),
605+
);
606+
607+
await tester.pumpAndSettle();
608+
609+
final PlatformMapStateRecorder map = platform.lastCreatedMap;
610+
611+
expect(map.circleUpdates.length, 1);
612+
});
582613
}

0 commit comments

Comments
 (0)