I have an action taken on a button click. The method looks like
void _buttonAction() async {
setState(() {
_loading = true;
});
// Api call takes place here
setState(() {
_loading = false;
});
}
In my widget test, after the first setState
I want to check whether my loading widget is displayed, but calling pump seems to progress through both the setState
so when I try to check for the loading widget it fails. If I comment out the second setState
then it is able to find the loading widget. How can I properly test this scenario? Here is my test code
testWidgets("Loading", (widgetTester) async {
final Api api = MockApi();
await widgetTester.pumpWidget(
MyWidget()
);
await widgetTester.tap(find.byType(TextButton));
await widgetTester.pump();
expect(find.byType(Loading), findsOneWidget);
});
Thanks!