Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mocktail_image_network): pass onDone callback when listening to stream #120

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ HttpClient _createHttpClient() {
).thenAnswer((invocation) {
final onData =
invocation.positionalArguments[0] as void Function(List<int>);
final onDone = invocation.namedArguments[#onDone] as void Function()?;
return Stream<List<int>>.fromIterable(<List<int>>[_transparentPixelPng])
.listen(onData);
.listen(onData, onDone: onDone);
});
when(() => request.headers).thenReturn(headers);
when(request.close).thenAnswer((_) async => response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:mocktail_image_network/mocktail_image_network.dart';
import 'package:test/test.dart';

void main() {
group('mockNetworkImageFor', () {
group('mockNetworkImages', () {
test(
'should properly mock getUrl and complete without exceptions',
() async {
Expand All @@ -27,5 +27,24 @@ void main() {
});
},
);

test('should properly pass through onDone', () async {
await mockNetworkImages(() async {
final client = HttpClient()..autoUncompress = false;
final request = await client.getUrl(Uri.https('', ''));
final response = await request.close();
var onDoneCalled = false;
final onDone = () {
onDoneCalled = true;
};

response.listen((_) {}, onDone: onDone);

// Wait for all microtasks to run
await Future<void>.delayed(Duration.zero);

expect(onDoneCalled, isTrue);
});
});
});
}