add description to by-predicate finders (#6362)

Add an option to provide a custom description to predicate
finders. Without a custom description we default to printing the
predicate function's signature, which is not all that useful.

Use this new option in the driver extension to print the text of the
sought after tooltip.
This commit is contained in:
Yegor
2016-10-17 17:16:22 -07:00
committed by GitHub
parent 08ba8dc495
commit 995fcdc92b
3 changed files with 64 additions and 13 deletions

View File

@@ -104,4 +104,37 @@ void main() {
});
});
group('find.byElementPredicate', () {
testWidgets('fails with a custom description in the message', (WidgetTester tester) async {
await tester.pumpWidget(new Text('foo'));
String customDescription = 'custom description';
TestFailure failure;
try {
expect(find.byElementPredicate((_) => false, description: customDescription), findsOneWidget);
} catch(e) {
failure = e;
}
expect(failure, isNotNull);
expect(failure.message, contains('Actual: ?:<zero widgets with $customDescription'));
});
});
group('find.byWidgetPredicate', () {
testWidgets('fails with a custom description in the message', (WidgetTester tester) async {
await tester.pumpWidget(new Text('foo'));
String customDescription = 'custom description';
TestFailure failure;
try {
expect(find.byWidgetPredicate((_) => false, description: customDescription), findsOneWidget);
} catch(e) {
failure = e;
}
expect(failure, isNotNull);
expect(failure.message, contains('Actual: ?:<zero widgets with $customDescription'));
});
});
}