I have a Widget that relies on a provider. I want to run widget tests on this widget. I assume because widget testing is directly at that node in the tree, it is reasonable to get errors such as:
* Ensure the Provider<Appointments> is an ancestor to this InstallMonitorPage Widget
(note: the name of my Provider is . May main includes:
return MultiProvider(
providers: [
Provider<AuthBase>(
builder: (context) => Auth(),
),
Provider<Appointments>(
builder: (context) => Appointments(),
)
],
child: MaterialApp(
title: title,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: LaunchPage()),
);
Is there a syntax/way to include the Provider when running a widget test on a widget lower down the widget tree?
You could try something like this:
await tester.pumpWidget(MultiProvider(
providers: [
Provider<AuthBase>(
builder: (context) => Auth(),
),
Provider<Appointments>(
builder: (context) => Appointments(),
)
],
child: Builder(
builder: (_) => YourWidgeToTest(),
),
),);
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