How to test tedirect to another widget (integration_test in flutter/dart)?

26 views Asked by At

I'm testing the login page, entering the login information and expecting it to go to the main page, but when the button is taped, the function executes exactly until Get.offNamed and nothing happens, please help

    testWidgets('login', (tester) async {
      app.main();
      final FlutterExceptionHandler? originalOnError = FlutterError.onError;
      await tester.pumpAndSettle();
      await tester.pumpWidget(MaterialApp(home: LoginWidget()));

      Finder loginBtn = find.byKey(const Key('login'));

      Finder emailField = find.byKey(const Key('email'));
      Finder passwordField = find.byKey(const Key('password'));
      FlutterError.onError = originalOnError;
      await tester.enterText(
          emailField, dotenv.env['TEST_USER_EMAIL'].toString());
      await Future.delayed(const Duration(seconds: 2));
      await tester.enterText(
          passwordField, dotenv.env['TEST_PASSWORD'].toString());
      await Future.delayed(const Duration(seconds: 2));
      await tester.tap(loginBtn);
      await tester.pumpAndSettle();

      expect(find.byType(ClientPredictionWidget), findsOneWidget);
      //error here (Expected: exactly one matching node in the widget tree)
    });```


I can't understand why this doesn't work (
0

There are 0 answers