flutter_test_ui 2.0.0 copy "flutter_test_ui: ^2.0.0" to clipboard
flutter_test_ui: ^2.0.0 copied to clipboard

Wrapper for flutter_test that adds a tester argument to setUp and tearDown functions

flutter_test_ui #

Wrapper of testWidgets, setUp, and tearDown that provide the WidgetTesterCallback argument to the set-up and tear-down functions: testUI, setUpUI, and tearDownUI.

This allows a single set-up to be shared by several tests and the set-up to be continued in subgroups. In particular, it allows test to be written in rspec style for better readability.

group("testUI and setUpUI example test", () {
  setUpUI((tester) async {
    await tester.pumpWidget(MaterialApp(
      home: Builder(
        builder: (context) => GestureDetector(
          onTap: () => Navigator.of(context).push(
            MaterialPageRoute<void>(
              builder: (context) => Container(
                color: Colors.green,
                child: const Text("page 2"),
              ),
            ),
          ),
          child: Container(
            color: Colors.red,
            child: const Text("page 1"),
          ),
        ),
      ),
    ));
  });

  testUI("first page is shown", (tester) async {
    expect(find.text("page 1"), findsOneWidget);
  });

  group("tapping the text", () {
    setUpUI((tester) async {
      await tester.tap(find.text("page 1"));
      await tester.pumpAndSettle();
    });

    testUI("second page is shown", (tester) async {
      expect(find.text("page 2"), findsOneWidget);
    });

    group("pop the second page", () {
      setUpUI((tester) async {
        final nav = tester.state<NavigatorState>(find.byType(Navigator));
        nav.pop();
        await tester.pumpAndSettle();
      });

      testUI("second page isn't visible anymore", (tester) async {
        expect(find.text("page 2"), findsNothing);
      });

      testUI("first page is visible again", (tester) async {
        expect(find.text("page 1"), findsOneWidget);
      });
    });
  });
});
12
likes
80
points
275
downloads

Publisher

verified publisherspkersten.nl

Weekly Downloads

Wrapper for flutter_test that adds a tester argument to setUp and tearDown functions

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_test, meta

More

Packages that depend on flutter_test_ui