Home > front end >  Flutter Firebase: testing gets hung up on initalizeApp()
Flutter Firebase: testing gets hung up on initalizeApp()

Time:01-13

I have a widget that I am trying to test which relies on a Firestore Repository. The code is as follows:

void main() {
  group('AdminVerificationScreen', () {
    testWidgets('renders correctly', (WidgetTester tester) async {
      WidgetsFlutterBinding.ensureInitialized();

      //pump the widget using a bloc provider and a multirepository provider
      await Firebase.initializeApp(
        options: DefaultFirebaseOptions.currentPlatform,
      );

      await tester.pumpWidget(
        MultiRepositoryProvider(
          providers: [
            RepositoryProvider(
              create: (_) => FirestoreRepository(),
            ),
            RepositoryProvider(
              create: (context) => TypesenseRepository(),
            ),
          ],
          child: MultiBlocProvider(
            providers: [
              BlocProvider<AdminVerificationBloc>(
                create: (context) => AdminVerificationBloc(
                    databaseRepository: context.read<FirestoreRepository>(),
                    typesenseRepository: context.read<TypesenseRepository>()),
              ),
            ],
            child: MaterialApp(
              home: AdminVerificationScreen(),
            ),
          ),
        ),
      );

      //expect the widget to be found
      expect(find.byType(AdminVerificationScreen), findsOneWidget);
    });
  });
}

The issue is at the intialize app. It gets hung up and will not proceed, but removing it gives the error:

[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()

Anyone see what im doing wrong?

Thanks!

CodePudding user response:

It looks like you're missing async after you call main(), so you're not giving Firebase a chance to complete its initialization.

Try this instead:

Future<void> main() async {
...
  • Related