Skip to content

Commit

Permalink
fix(mocktail_image_network): pass onDone callback (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirpal committed Mar 9, 2022
1 parent 67f85d6 commit 58c6aa3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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);
});
});
});
}

0 comments on commit 58c6aa3

Please sign in to comment.