Async testing with FutureBuilders #794
Replies: 1 comment
-
Turns out I was not awaiting some UI transition because the Widget under test was in another tab. In general you are probably going to need all three of the following pumps if you do more complex widget testing with // For more complex widget actions like tabs
await tester.pump(const Duration(milliseconds: 100));
// For pumping floor async calls themselves
await Future<void>.delayed(const Duration(milliseconds: 100));
// For regular widget actions like button clicks
await tester.pump(); So in my particular example I was testing a the third tab of a screen that was itself part of a popup. I needed to open said tab like this in the test for all the async operations to perform as expected: var graphsTab = find.text('Graphs');
await tester.tap(graphsTab);
await tester.pump(const Duration(milliseconds: 100));
await tester.pump(const Duration(milliseconds: 100));
await Future<void>.delayed(const Duration(milliseconds: 100));
await tester.pumpAndSettle(); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When working with a in-memory database for unit tests
await Future<void>.delayed(const Duration(milliseconds: 100));
is enough to get the async methods using Floor to complete. However, when I use aFutureBuilder
then theFuture
does not complete until after the test completed.I am using a normal
FutureBulder
and theFuture
is stored in the State:My test in question:
I also ran into the same issue before but using
await Future<void>.delayed(const Duration(milliseconds: 100));
fixed it for me. This is not the case for the widgets using a FutureBuilder.Has anyone ideas to fix this?
Beta Was this translation helpful? Give feedback.
All reactions