简体   繁体   中英

Flutter Firebase: testing gets hung up on initalizeApp()

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!

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 {
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM