Home > Mobile >  Why widgets are not visible when running the widget test?
Why widgets are not visible when running the widget test?

Time:12-07

I'm simply trying to imetiate the enter image description here

I assume that I'm not doing something special here, it's just a widget basically with three Texts.

All I need is to verify that the subwidgets (the Texts) are visible when providing the values of the fields. What am I missing here?!

Please note I tried to use the find.text("...") instead of keys, but it didn't work as well.

CodePudding user response:

Wrap the OrderDetailsItemWidget in MaterialApp

void main() {
  testWidgets(
"OrderDetailsItemWidget - all fields are provided (quantity, name, and 
    subtext)",
    (WidgetTester tester) async {
  
  // Arrange, Act
  await tester.pumpWidget(
    MaterialApp(
      home: const OrderDetailsItemWidget(
        1,
        "name",
        "subtext",
      ),
    ),
  );

  // Assert
  expect(
    find.byKey(const Key("order_details_item_widget_quantity")),
    findsOneWidget,
  );
  expect(
    find.byKey(const Key("order_details_item_widget_name")),
    findsOneWidget,
  );
  expect(
    find.byKey(const Key("order_details_item_widget_subtext")),
    findsOneWidget,
   );
  },
 );
}
  • Related