Skip to content

Instantly share code, notes, and snippets.

@densa
Created September 7, 2022 18:58
Show Gist options
  • Save densa/e49e23045a206d6c5bcff9197e8699a2 to your computer and use it in GitHub Desktop.
Save densa/e49e23045a206d6c5bcff9197e8699a2 to your computer and use it in GitHub Desktop.
// Parent with a child & grand child
class ParentWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChildWidget(
child: GrandChildWidget(),
);
}
}
// Tests
void main() {
testWidgets('parent, child & grand-child hierarchy', (WidgetTester tester) async {
Widget parentWidget = ParentWidget();
await tester.pumpWidget(parentWidget);
final childFinder = find.descendant(of: find.byWidget(parentWidget), matching: find.byType(ChildWidget));
expect(childFinder, findsOneWidget);
final grandChildFinder = find.descendant(of: find.byWidget(parentWidget), matching: find.byType(GrandChildWidget));
expect(grandChildFinder, findsOneWidget);
final parentFinder = find.ancestor(of: find.byWidget(childWidget), matching: find.byType(ParentWidget));
expect(parentFinder, findsOneWidget);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment