From 5d4573a8394596183147fef3b0614bd489f79710 Mon Sep 17 00:00:00 2001 From: Roc Boronat Date: Fri, 19 Jan 2024 07:20:27 +0100 Subject: [PATCH 1/8] docs(mocktail): update `README.md` to include `any(that: ...)` (#226) --- packages/mocktail/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/mocktail/README.md b/packages/mocktail/README.md index 339f570..ff2adc5 100644 --- a/packages/mocktail/README.md +++ b/packages/mocktail/README.md @@ -83,6 +83,7 @@ expect(cat.likes('fish', isHungry: false), isTrue); // You can verify the interaction for specific arguments. verify(() => cat.likes('fish', isHungry: false)).called(1); +verify(() => cat.likes(any(that: isA().having((food) => food.name, 'name', 'Fish')))).called(1); // You can stub a method using argument matcher: `any`. // When stubbing a positional argument, use `any()`. From 53e8132e05216a95fc5951a4558a1130b3782f1f Mon Sep 17 00:00:00 2001 From: Anton Borries Date: Fri, 19 Jan 2024 07:43:20 +0100 Subject: [PATCH 2/8] feat(mocktail_image_network): add customizable `imageBytes` (#214) --- .../lib/src/mocktail_image_network.dart | 11 ++++++---- .../test/mocktail_image_network_test.dart | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/mocktail_image_network/lib/src/mocktail_image_network.dart b/packages/mocktail_image_network/lib/src/mocktail_image_network.dart index 50461d5..2a6b0f3 100644 --- a/packages/mocktail_image_network/lib/src/mocktail_image_network.dart +++ b/packages/mocktail_image_network/lib/src/mocktail_image_network.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'dart:io'; +import 'dart:typed_data'; import 'package:mocktail/mocktail.dart'; @@ -39,10 +40,12 @@ import 'package:mocktail/mocktail.dart'; /// } /// ``` /// {@endtemplate} -T mockNetworkImages(T Function() body) { +T mockNetworkImages(T Function() body, {Uint8List? imageBytes}) { return HttpOverrides.runZoned( body, - createHttpClient: (_) => _createHttpClient(), + createHttpClient: (_) => _createHttpClient( + data: imageBytes ?? _transparentPixelPng, + ), ); } @@ -59,7 +62,7 @@ class _MockHttpClientResponse extends Mock implements HttpClientResponse {} class _MockHttpHeaders extends Mock implements HttpHeaders {} -HttpClient _createHttpClient() { +HttpClient _createHttpClient({required List data}) { final client = _MockHttpClient(); final request = _MockHttpClientRequest(); final response = _MockHttpClientResponse(); @@ -79,7 +82,7 @@ HttpClient _createHttpClient() { final onData = invocation.positionalArguments[0] as void Function(List); final onDone = invocation.namedArguments[#onDone] as void Function()?; - return Stream>.fromIterable(>[_transparentPixelPng]) + return Stream>.fromIterable(>[data]) .listen(onData, onDone: onDone); }); when(() => request.headers).thenReturn(headers); diff --git a/packages/mocktail_image_network/test/mocktail_image_network_test.dart b/packages/mocktail_image_network/test/mocktail_image_network_test.dart index cf6bd98..67cb956 100644 --- a/packages/mocktail_image_network/test/mocktail_image_network_test.dart +++ b/packages/mocktail_image_network/test/mocktail_image_network_test.dart @@ -44,5 +44,27 @@ void main() { expect(onDoneCalled, isTrue); }); }); + + test('should properly use custom imageBytes', () async { + final greenPixel = base64Decode( + '''iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAEBgIApD5fRAAAAABJRU5ErkJggg==''', + ); + await mockNetworkImages( + () async { + final client = HttpClient()..autoUncompress = false; + final request = await client.getUrl(Uri.https('')); + final response = await request.close(); + final data = []; + + response.listen(data.addAll); + + // Wait for all microtasks to run + await Future.delayed(Duration.zero); + + expect(data, equals(greenPixel)); + }, + imageBytes: greenPixel, + ); + }); }); } From 19cef6c84eab292a6af0b1597813240d128a4db0 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Fri, 19 Jan 2024 00:45:14 -0600 Subject: [PATCH 3/8] chore: remove deprecated lint rules --- analysis_options.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 7bd5e9c..b590706 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -76,7 +76,6 @@ linter: - implicit_call_tearoffs - implicit_reopen - invalid_case_patterns - - iterable_contains_unrelated_type - join_return_with_assignment - leading_newlines_in_multiline_strings - library_annotations @@ -84,7 +83,6 @@ linter: - library_prefixes - library_private_types_in_public_api - lines_longer_than_80_chars - - list_remove_unrelated_type - literal_only_boolean_expressions - missing_whitespace_between_adjacent_strings - no_adjacent_strings_in_list @@ -198,4 +196,4 @@ linter: - use_test_throws_matchers - use_to_and_as_if_applicable - valid_regexps - - void_checks \ No newline at end of file + - void_checks From 4aea1f1fdee27ad213d26b6b87c08b96d0ec453b Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Fri, 19 Jan 2024 00:46:44 -0600 Subject: [PATCH 4/8] chore: update LICENSE year --- packages/mocktail/LICENSE | 2 +- packages/mocktail_image_network/LICENSE | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/mocktail/LICENSE b/packages/mocktail/LICENSE index b23e274..adc3c2c 100644 --- a/packages/mocktail/LICENSE +++ b/packages/mocktail/LICENSE @@ -1,5 +1,5 @@ The MIT License (MIT) -Copyright (c) 2023 Felix Angelov +Copyright (c) 2024 Felix Angelov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/packages/mocktail_image_network/LICENSE b/packages/mocktail_image_network/LICENSE index b23e274..adc3c2c 100644 --- a/packages/mocktail_image_network/LICENSE +++ b/packages/mocktail_image_network/LICENSE @@ -1,5 +1,5 @@ The MIT License (MIT) -Copyright (c) 2023 Felix Angelov +Copyright (c) 2024 Felix Angelov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation From 633471e4a128c36ecd795e18549361c62835f993 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Fri, 19 Jan 2024 00:51:48 -0600 Subject: [PATCH 5/8] chore(mocktail_image_network): v1.1.0 (#227) --- packages/mocktail_image_network/CHANGELOG.md | 6 ++++++ packages/mocktail_image_network/README.md | 4 ++-- packages/mocktail_image_network/pubspec.yaml | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/mocktail_image_network/CHANGELOG.md b/packages/mocktail_image_network/CHANGELOG.md index bb5f620..538d9f3 100644 --- a/packages/mocktail_image_network/CHANGELOG.md +++ b/packages/mocktail_image_network/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.1.0 + +- feat: add customizable `imageBytes` to `mockNetworkImages` ([#214](https://github.com/felangel/mocktail/issues/214)) +- chore: remove deprecated lint rules +- docs: adjust `LICENSE` year + # 1.0.0 - refactor: use more strict analysis options ([#203](https://github.com/felangel/mocktail/issues/203)) diff --git a/packages/mocktail_image_network/README.md b/packages/mocktail_image_network/README.md index f894b03..49d5f49 100644 --- a/packages/mocktail_image_network/README.md +++ b/packages/mocktail_image_network/README.md @@ -9,7 +9,7 @@ Mock `Image.network` in your widget tests with confidence using [mocktail](https --- -## How to use +## Usage If you want to test a widget with a similar structure to this one: @@ -40,7 +40,7 @@ void main() { } ``` -### Why should you use mocktail_image_network +### Why should you use `mocktail_image_network` If your application uses [Image.network](https://api.flutter.dev/flutter/widgets/Image/Image.network.html) to present images hosted in a URL, you will notice that your widget tests fail diff --git a/packages/mocktail_image_network/pubspec.yaml b/packages/mocktail_image_network/pubspec.yaml index ce07946..16fc603 100644 --- a/packages/mocktail_image_network/pubspec.yaml +++ b/packages/mocktail_image_network/pubspec.yaml @@ -1,6 +1,6 @@ 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: 1.0.0 +version: 1.1.0 repository: https://github.com/felangel/mocktail homepage: https://github.com/felangel/mocktail/tree/main/packages/mocktail_image_network topics: [mock, test] From ca9f35e5d869e4b82174c466b3d5d4205395e698 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Fri, 19 Jan 2024 00:58:01 -0600 Subject: [PATCH 6/8] chore(mocktail): v1.0.3 (#228) --- packages/mocktail/CHANGELOG.md | 6 ++++++ packages/mocktail/pubspec.yaml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/mocktail/CHANGELOG.md b/packages/mocktail/CHANGELOG.md index 7ac47ff..28636ab 100644 --- a/packages/mocktail/CHANGELOG.md +++ b/packages/mocktail/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.0.3 + +- docs: update ` README.md`` to include `any(that: ...)` ([#226](https://github.com/felangel/mocktail/issues/226)) +- chore: update LICENSE year +- chore: remove deprecated lint rules + # 1.0.2 - chore(deps): allow pkg:test_api >=0.7.0 ([#220](https://github.com/felangel/mocktail/issues/220)) diff --git a/packages/mocktail/pubspec.yaml b/packages/mocktail/pubspec.yaml index aa08a48..9e87ef7 100644 --- a/packages/mocktail/pubspec.yaml +++ b/packages/mocktail/pubspec.yaml @@ -1,6 +1,6 @@ name: mocktail description: A Dart mock library which simplifies mocking with null safety support and no manual mocks or code generation. -version: 1.0.2 +version: 1.0.3 repository: https://github.com/felangel/mocktail homepage: https://github.com/felangel/mocktail/tree/main/packages/mocktail topics: [mock, test] From d4df7d2d2c35defebe3a76375a6be8c21fdb0675 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Fri, 19 Jan 2024 01:02:25 -0600 Subject: [PATCH 7/8] docs(mocktail): adjust `README.md` snippet for `any(that: ...)` --- packages/mocktail/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/mocktail/README.md b/packages/mocktail/README.md index ff2adc5..e208c3e 100644 --- a/packages/mocktail/README.md +++ b/packages/mocktail/README.md @@ -83,7 +83,9 @@ expect(cat.likes('fish', isHungry: false), isTrue); // You can verify the interaction for specific arguments. verify(() => cat.likes('fish', isHungry: false)).called(1); -verify(() => cat.likes(any(that: isA().having((food) => food.name, 'name', 'Fish')))).called(1); + +// Or alternatively use any(that: ...) to use a matcher. +verify(() => cat.likes(any(that: isA().having((food) => food, 'name', 'fish')))).called(1); // You can stub a method using argument matcher: `any`. // When stubbing a positional argument, use `any()`. From fdffdc520b7433f19fe5b6fcbed500c36a858716 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Fri, 19 Apr 2024 23:07:48 -0500 Subject: [PATCH 8/8] chore(mocktail): fix minor typo in `CHANGELOG.md` --- packages/mocktail/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mocktail/CHANGELOG.md b/packages/mocktail/CHANGELOG.md index 28636ab..27b4faa 100644 --- a/packages/mocktail/CHANGELOG.md +++ b/packages/mocktail/CHANGELOG.md @@ -1,6 +1,6 @@ # 1.0.3 -- docs: update ` README.md`` to include `any(that: ...)` ([#226](https://github.com/felangel/mocktail/issues/226)) +- docs: update ` README.md` to include `any(that: ...)` ([#226](https://github.com/felangel/mocktail/issues/226)) - chore: update LICENSE year - chore: remove deprecated lint rules