Unverified Commit 5665655d authored by Ivan Inozemtsev's avatar Ivan Inozemtsev Committed by GitHub

Add support for `Future<List<int>?>` to `MatchesGoldenFile` (#132965)

Otherwise when tests use `expectLater(getBytesOrNull(), matchesGoldenFile(...))`, they may fail in sound null safety mode and pass in weak null safety mode.

Fixes https://github.com/flutter/flutter/issues/132964
parent 18432377
......@@ -60,8 +60,9 @@ class MatchesGoldenFile extends AsyncMatcher {
final Uri testNameUri = goldenFileComparator.getTestUri(key, version);
Uint8List? buffer;
if (item is Future<List<int>>) {
buffer = Uint8List.fromList(await item);
if (item is Future<List<int>?>) {
final List<int>? bytes = await item;
buffer = bytes == null ? null : Uint8List.fromList(bytes);
} else if (item is List<int>) {
buffer = Uint8List.fromList(item);
}
......
......@@ -470,6 +470,14 @@ void main() {
expect(comparator.imageBytes, equals(<int>[1, 2]));
expect(comparator.golden, Uri.parse('foo.png'));
});
testWidgets('future nullable list of integers',
(WidgetTester tester) async {
await expectLater(Future<List<int>?>.value(<int>[1, 2]), matchesGoldenFile('foo.png'));
expect(comparator.invocation, _ComparatorInvocation.compare);
expect(comparator.imageBytes, equals(<int>[1, 2]));
expect(comparator.golden, Uri.parse('foo.png'));
});
});
group('does not match', () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment