Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use flutter_test matchers where helpful, via flutter_checks #952

Open
gnprice opened this issue Sep 18, 2024 · 0 comments
Open

Use flutter_test matchers where helpful, via flutter_checks #952

gnprice opened this issue Sep 18, 2024 · 0 comments
Labels
Milestone

Comments

@gnprice
Copy link
Member

gnprice commented Sep 18, 2024

This is a followup to #232, which is now complete.

In Flutter widget tests written with the venerable expect API, it's common to have expectations like

    expect(find.whatever(), findsOne);

using the matchers findsOne, findsNothing, and findsWidgets. See docs.

We're using package:checks instead, which is the projected, still-beta, successor to expect with a fancy type-safe API, so these "matchers" like findsOne aren't available; and until recently we didn't have great analogues of them. So one thing we currently often do in place of findsOne is

    tester.widget(find.whatever());

which will indeed throw if there isn't exactly one such widget, but it's not great because it doesn't look like something intended as one of the checks that are the payload of the test — it looks like it's just part of the test's setup (and on top of that, isn't doing anything). A bit of discussion here: #207 (comment)


There's no longer a reason to write expectations that way. Instead we can use the handy new flutter_checks package to write:

    check(find.whatever()).findsOne();

which is clear that the intent is to check an expectation. It's also a very straightforward translation of the expect form, so it's easy to migrate.

There's no rush to migrate all our existing tests, but this issue is to track eventually doing so. In the meantime we should generally write new tests in the new style.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

1 participant