Flutter test not able to find custom widget

Viewed 49

I have written a test case to find a custom widget :

Widget createWidgetForTesting({required Widget child}) {
    return MediaQuery(data: const MediaQueryData(), child: GetMaterialApp(home: child));
  }

  testWidgets("if start-page contains logo", (WidgetTester tester) async {
    await tester.pumpWidget(createWidgetForTesting(child: const StartView()));
    expect(find.byWidget(const AppLogoItem()), findsOneWidget);
  });

I want to find the custom widget AppLogo inside StartView.

Code for StartView :

import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:ride_mobile/app/utils/app_logo_item.dart';

import '../controllers/start_controller.dart';

class StartView extends GetView<StartController> {
  const StartView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: const [AppLogoItem()],
      ),
    );
  }
}

But by test case if failing because :

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 (AppLogoItem) (ignoring offstage
widgets)>
   Which: means none were found but one was expected
0 Answers
Related