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
This commit is contained in:
parent
184323777a
commit
5665655d39
@ -60,8 +60,9 @@ class MatchesGoldenFile extends AsyncMatcher {
|
|||||||
final Uri testNameUri = goldenFileComparator.getTestUri(key, version);
|
final Uri testNameUri = goldenFileComparator.getTestUri(key, version);
|
||||||
|
|
||||||
Uint8List? buffer;
|
Uint8List? buffer;
|
||||||
if (item is Future<List<int>>) {
|
if (item is Future<List<int>?>) {
|
||||||
buffer = Uint8List.fromList(await item);
|
final List<int>? bytes = await item;
|
||||||
|
buffer = bytes == null ? null : Uint8List.fromList(bytes);
|
||||||
} else if (item is List<int>) {
|
} else if (item is List<int>) {
|
||||||
buffer = Uint8List.fromList(item);
|
buffer = Uint8List.fromList(item);
|
||||||
}
|
}
|
||||||
|
@ -470,6 +470,14 @@ void main() {
|
|||||||
expect(comparator.imageBytes, equals(<int>[1, 2]));
|
expect(comparator.imageBytes, equals(<int>[1, 2]));
|
||||||
expect(comparator.golden, Uri.parse('foo.png'));
|
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', () {
|
group('does not match', () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user