zulip-flutter
zulip-flutter copied to clipboard
Find a package:checks analogue of flutter_test's widget-finder matchers
In Flutter widget tests written with the venerable expect
API, it's common to have expectations like
expect(find.whatever(), findsOneWidget);
using the matchers findsOneWidget, 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 findsOneWidget aren't available; and we don't currently have great analogues of them. One thing we currently often do in place of findsOneWidget
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: https://github.com/zulip/zulip-flutter/pull/207#discussion_r1256975139
Shouldn't be hard to write appropriate checks in the package:checks
API. We should do that, convert our existing tests, and also make sure there's a discussion upstream about there being good support for using package:checks
with package:flutter_test
before the former is rolled out as stable.