Skip to content

Commit

Permalink
Avoid catching errors in TextPainter tests (#127307)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgucio authored May 23, 2023
1 parent 11cb291 commit 25d2f90
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions packages/flutter/test/painting/text_painter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,14 @@ void main() {

test('TextPainter error test', () {
final TextPainter painter = TextPainter(textDirection: TextDirection.ltr);
Object? e;
try {
painter.paint(MockCanvas(), Offset.zero);
} catch (exception) {
e = exception;
}

expect(
e.toString(),
contains('TextPainter.paint called when text geometry was not yet calculated'),
() => painter.paint(MockCanvas(), Offset.zero),
throwsA(isA<StateError>().having(
(StateError error) => error.message,
'message',
contains('TextPainter.paint called when text geometry was not yet calculated'),
)),
);
painter.dispose();
});
Expand Down Expand Up @@ -1310,15 +1309,13 @@ void main() {
PlaceholderDimensions(size: Size(50, 30), alignment: ui.PlaceholderAlignment.bottom),
]);

Object? e;
try {
painter.paint(MockCanvas(), Offset.zero);
} catch (exception) {
e = exception;
}
expect(
e.toString(),
contains('TextPainter.paint called when text geometry was not yet calculated'),
() => painter.paint(MockCanvas(), Offset.zero),
throwsA(isA<StateError>().having(
(StateError error) => error.message,
'message',
contains('TextPainter.paint called when text geometry was not yet calculated'),
)),
);
painter.dispose();
}, skip: isBrowser && !isCanvasKit); // https://github.com/flutter/flutter/issues/56308
Expand Down Expand Up @@ -1348,16 +1345,14 @@ void main() {
PlaceholderDimensions(size: Size(50, 30), alignment: ui.PlaceholderAlignment.bottom),
]);

Object? e;
try {
painter.paint(MockCanvas(), Offset.zero);
} catch (exception) {
e = exception;
}
// In tests, paint() will throw an UnimplementedError due to missing drawParagraph method.
expect(
e.toString(),
isNot(contains('TextPainter.paint called when text geometry was not yet calculated')),
() => painter.paint(MockCanvas(), Offset.zero),
isNot(throwsA(isA<StateError>().having(
(StateError error) => error.message,
'message',
contains('TextPainter.paint called when text geometry was not yet calculated'),
))),
);
painter.dispose();
}, skip: isBrowser && !isCanvasKit); // https://github.com/flutter/flutter/issues/56308
Expand Down

0 comments on commit 25d2f90

Please sign in to comment.