I'm trying to wait for some time after I tested tapping my button to then check the result with expect
. I'm using Future.delayed
for that. But that doesn't work for me. I'm getting a time out error.
TimeoutException after 0:00:05.000000: Test timed out after 5 seconds.
This is the code I use:
... // other tests
await tester.tap(find.widgetWithText(GestureDetector, "ref size"));
await new Future.delayed(new Duration(milliseconds: 50));
expect(testContainerState.childWidth, 50.0);
Does any one have an idea why this (imo) strange behavior occurs?
start(); // do something to wait for 2 seconds await Future. delayed(const Duration(seconds: 2), (){}); expect(timer. seconds, startTime - 2); });
So, to start out with a simpler answer the correct way to wait for a period of time in a flutter test is using tester. pump . await tester. pump(new Duration(milliseconds: 50));
So, to start out with a simpler answer the correct way to wait for a period of time in a flutter test is using tester.pump
.
await tester.pump(new Duration(milliseconds: 50));
The longer answer to why this happens has to do with the flutter testing environment. To make sure tests are reliable, even in the face of time-varying animations the environment mocks as much of the async behavior as possible, using utilities such as FakeAsync from package:quiver
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With