I have this test:
testWidgets('Controller must only be used with one widget at a time',
(WidgetTester tester) async {
final CustomAnimatedWidgetController controller = CustomAnimatedWidgetController();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Column(
children: [
CustomAnimatedWidget(
child: Container(),
controller: controller,
),
CustomAnimatedWidget(// this declaration will throw an exception from initState of this widget
child: Container(),
controller: controller,
),
],
),
),
),
);
expect(tester.takeException(), isInstanceOf<Exception>());
});
Which is guaranteed to throw an exception of type Exception
(due to using the controller two times), but the expect
is not catching the exception. Instead, the test fails and I see my exception thrown in the console.
But here and here they say this is how it must be used. What is wrong with the test?