Created
September 7, 2022 18:58
-
-
Save densa/e49e23045a206d6c5bcff9197e8699a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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