I was following this example to test if a CircularProgressIndicator is present in my view, but even though the Flutter build tree shows the widget is present, I keep getting the following exception:
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure was thrown running a test:
Expected: exactly one matching node in the widget tree
Actual: _WidgetFinder:<zero widgets with the given widget
(CircularProgressIndicator(<indeterminate>)) (ignoring offstage widgets)>
Which: means none were found but one was expected
When the exception was thrown, this was the stack:
#4 main.<anonymous closure> (file:///D:/xxxx/xxxx/xxxx/test/widget_test/widget_test.dart:173:5)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)
This was caught by the test expectation on the following line:
file:///D:/xxxx/xxxx/xxxx/test/widget_test/widget_test.dart line 173
The test description was:
ViewRequest: Waiting Types List
════════════════════════════════════════════════════════════════════════════════════════════════════
Edit
I've made a method that builds a MaterialApp with just a CircularProgressIndicator Widget as its "child":
Widget createMockViewRequest() {
return MaterialApp(
title: 'SmartDevice Simulator',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const CircularProgressIndicator());
}
And the following test still keeps failing with the same exception:
testWidgets('ViewRequest: Waiting Types List', (WidgetTester tester) async {
const childWidget = CircularProgressIndicator();
// Build our app and trigger a frame.
await tester.pumpWidget(createMockViewRequest());
// Verify that the page is loading until we receive the types.
expect(find.byWidget(childWidget), findsOneWidget);
await tester.pumpAndSettle();
});
Am I doing something wrong? Maybe the MaterialApp doesn't count as a container? But in that case I fail to understand why it should not.