Widget test with await is hanged when not using `runAsync` instead of showing error/warning message #5728
Comments
testWidgets is using a FakeAsync, and setUp's future is created outside that FakeAsync scope. |
This does look zone-related. I couldn't reproduce using just
Here's the plain code I used: import "dart:async";
import "package:quiver/testing/async.dart";
import "package:test/test.dart";
void main() {
Future future;
zoneChain() {
var zone = Zone.current;
var zones = [];
while(zone != null) {
zones.add(zone);
zone = zone.parent;
}
return zones.map((z) => z.hashCode).join(' < ');
}
setUp(() {
print('setUp zones: ${zoneChain()}');
future = new Future.value();
});
test("awaiting future with value from setUp works", () async {
var fakeAsync = new FakeAsync();
fakeAsync.run((_) async {
print('test zones: ${zoneChain()}');
await future;
});
fakeAsync.flushMicrotasks();
});
} |
@nex3 any ideas? |
Do we think this is a package:test bug, should we move it there? |
we've no idea. |
Is this still an issue? |
From what I understand you are supposed to use This works: testWidgets("awaiting future with value from setUp works",
(WidgetTester tester) async {
await tester.runAsync(() async {
await future;
});
}); Edit: added |
I believe @mdebbar saw this recently too. Yes, any real asynchronous work has to go through |
And don’t forget to await on runAsync: await tester.runAsync(() async {
await future;
}); |
Based on #5728 (comment), test still get hanged when not Code Sample
flutter doctor -v
|
The text was updated successfully, but these errors were encountered: