Skip to content

Commit

Permalink
feat(mocktail_image_network)!: upgrade to mocktail v0.0.2-dev.4 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored Mar 8, 2021
1 parent 016c762 commit 251a71d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
4 changes: 4 additions & 0 deletions packages/mocktail_image_network/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.0.2-dev.1

- **BREAKING**: feat!: upgrade to `mocktail v0.0.2-dev`'

# 0.0.1-dev.1

- feat: initial release 🎉
1 change: 0 additions & 1 deletion packages/mocktail_image_network/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ publish_to: none

environment:
sdk: ">=2.12.0-0 <3.0.0"
flutter: 1.25.0-8.3.pre

dependencies:
flutter:
Expand Down
29 changes: 19 additions & 10 deletions packages/mocktail_image_network/lib/src/mocktail_image_network.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ T mockNetworkImages<T>(T Function() body) {
}

class _MockHttpClient extends Mock implements HttpClient {
_MockHttpClient() {
registerFallbackValue<void Function(List<int>)>((List<int> _) {});
registerFallbackValue<Uri>(Uri());
}

@override
set autoUncompress(bool _autoUncompress) {}
}
Expand All @@ -62,22 +67,26 @@ HttpClient _createHttpClient() {
final request = _MockHttpClientRequest();
final response = _MockHttpClientResponse();
final headers = _MockHttpHeaders();
when(response)
.calls(#compressionState)
when(() => response.compressionState)
.thenReturn(HttpClientResponseCompressionState.notCompressed);
when(response).calls(#contentLength).thenReturn(_transparentPixelPng.length);
when(response).calls(#statusCode).thenReturn(HttpStatus.ok);
when(response).calls(#listen).thenAnswer((invocation) {
when(() => response.contentLength).thenReturn(_transparentPixelPng.length);
when(() => response.statusCode).thenReturn(HttpStatus.ok);
when(
() => response.listen(
any(),
onDone: any(named: 'onDone'),
onError: any(named: 'onError'),
cancelOnError: any(named: 'cancelOnError'),
),
).thenAnswer((invocation) {
final onData =
invocation.positionalArguments[0] as void Function(List<int>);
return Stream<List<int>>.fromIterable(<List<int>>[_transparentPixelPng])
.listen(onData);
});
when(request).calls(#headers).thenReturn(headers);
when(request).calls(#close).thenAnswer((_) async => response);
when(client)
.calls(#getUrl)
.withArgs(positional: [any]).thenAnswer((_) async => request);
when(() => request.headers).thenReturn(headers);
when(request.close).thenAnswer((_) async => response);
when(() => client.getUrl(any())).thenAnswer((_) async => request);
return client;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/mocktail_image_network/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: mocktail_image_network
description: A Dart package which allows you to mock Image.network in your widget tests with confidence using the mocktail package.
version: 0.0.1-dev.1
version: 0.0.2-dev.1
repository: https://github.com/felangel/mocktail
homepage: https://github.com/felangel/mocktail/tree/main/packages/mocktail_image_network

environment:
sdk: ">=2.12-0-0 <3.0.0"

dependencies:
mocktail: ^0.0.1-dev.10
mocktail: ">=0.0.2-dev.4 <0.0.2"

dev_dependencies:
coverage: ^0.14.2
test: ">=1.16.0-nullsafety.13 <1.16.0"
test: ^1.16.0

0 comments on commit 251a71d

Please sign in to comment.