-1

i read flutter's doc but i couldn't test button's action , i tried to do it this way, the button is children of PrivacyPolicyCard, and when clicked goes to the next page

testWidgets(
  "TextButton Acept",
  (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(
      home: PrivacyPolicyCard(),
    ));
    final buton = find.byKey(Key("bt-acept"), skipOffstage: false);
    await tester.ensureVisible(buton);

    expect(find.bySemanticsLabel("Button Acept"), findsOneWidget);
    await tester.tap(buton);
    await tester.pumpAndSettle(Duration(seconds: 2));
    expect(find.text("Next Page"), findsOneWidget);
    await tester.printToConsole("test passed");
    
  },
);

how do I find out if the button's action went to the next page?

1 Answers1

0

The NavigationObserver class would help you to achieve what you want.

if you create a class

import 'package:mocktail/mocktail.dart';

class MockNavigationObserver extends Mock implements NavigationObserver {}

and pass the instance of it to your instantiation

await tester.pumpWidget(MaterialApp(
   home: PrivacyPolicyCard(),
   navigationObservers: [mockObserver],
));

then you'd be able to detect if the actual push has happened:

verify(mockObserver.didPush(any, any));

Hope this helps!