Skip to content

Commit ae86ae6

Browse files
committed
test(widgets): scope SheetHandle container finders to its subtree
find.byType(Container) matched the whole pumped tree, so the assertions would become ambiguous if the test scaffolding ever gained a Container of its own. Scope to SheetHandle's descendants and assert a single match before reading the widget. Addresses review feedback on #501. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017B31wKKL578bV18hcpXyE2
1 parent 7b1cbd3 commit ae86ae6

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

test/widgets/sheet_handle_test.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ import 'package:flutter_test/flutter_test.dart';
55

66
void main() {
77
group('SheetHandle', () {
8+
// Scoped to SheetHandle's own subtree so the finders stay unambiguous
9+
// if the surrounding test scaffolding ever gains its own Containers.
10+
final handleContainer = find.descendant(
11+
of: find.byType(SheetHandle),
12+
matching: find.byType(Container),
13+
);
14+
815
testWidgets('renders a 32x4 rounded container', (tester) async {
916
await tester.pumpWidget(
1017
const MaterialApp(home: Scaffold(body: SheetHandle())),
1118
);
1219

13-
final container = tester.widget<Container>(find.byType(Container));
20+
expect(handleContainer, findsOneWidget);
21+
final container = tester.widget<Container>(handleContainer);
1422
expect(
1523
container.constraints,
1624
const BoxConstraints.tightFor(width: 32, height: 4),
@@ -26,10 +34,7 @@ void main() {
2634
);
2735

2836
expect(
29-
find.ancestor(
30-
of: find.byType(Container),
31-
matching: find.byType(Center),
32-
),
37+
find.ancestor(of: handleContainer, matching: find.byType(Center)),
3338
findsOneWidget,
3439
);
3540
});
@@ -78,7 +83,8 @@ void main() {
7883
),
7984
);
8085

81-
final container = tester.widget<Container>(find.byType(Container));
86+
expect(handleContainer, findsOneWidget);
87+
final container = tester.widget<Container>(handleContainer);
8288
final decoration = container.decoration! as BoxDecoration;
8389
expect(decoration.color, lightTheme.colorScheme.onSurfaceVariant);
8490
});

0 commit comments

Comments
 (0)