Skip to content

Commit

Permalink
Merge branch 'main' into add_trace_to_when_stateError
Browse files Browse the repository at this point in the history
  • Loading branch information
tomconnell-wf authored May 3, 2024
2 parents 394fc07 + fdffdc5 commit df3f363
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 13 deletions.
4 changes: 1 addition & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,13 @@ linter:
- implicit_call_tearoffs
- implicit_reopen
- invalid_case_patterns
- iterable_contains_unrelated_type
- join_return_with_assignment
- leading_newlines_in_multiline_strings
- library_annotations
- library_names
- 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
Expand Down Expand Up @@ -198,4 +196,4 @@ linter:
- use_test_throws_matchers
- use_to_and_as_if_applicable
- valid_regexps
- void_checks
- void_checks
6 changes: 6 additions & 0 deletions packages/mocktail/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
2 changes: 1 addition & 1 deletion packages/mocktail/LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions packages/mocktail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ expect(cat.likes('fish', isHungry: false), isTrue);
// You can verify the interaction for specific arguments.
verify(() => cat.likes('fish', isHungry: false)).called(1);
// Or alternatively use any(that: ...) to use a matcher.
verify(() => cat.likes(any(that: isA<String>().having((food) => food, 'name', 'fish')))).called(1);
// You can stub a method using argument matcher: `any`.
// When stubbing a positional argument, use `any()`.
// When stubbing a named argument, use `any(named: '<argName>`)`.
Expand Down
2 changes: 1 addition & 1 deletion packages/mocktail/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
6 changes: 6 additions & 0 deletions packages/mocktail_image_network/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
2 changes: 1 addition & 1 deletion packages/mocktail_image_network/LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/mocktail_image_network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:mocktail/mocktail.dart';

Expand Down Expand Up @@ -39,10 +40,12 @@ import 'package:mocktail/mocktail.dart';
/// }
/// ```
/// {@endtemplate}
T mockNetworkImages<T>(T Function() body) {
T mockNetworkImages<T>(T Function() body, {Uint8List? imageBytes}) {
return HttpOverrides.runZoned(
body,
createHttpClient: (_) => _createHttpClient(),
createHttpClient: (_) => _createHttpClient(
data: imageBytes ?? _transparentPixelPng,
),
);
}

Expand All @@ -59,7 +62,7 @@ class _MockHttpClientResponse extends Mock implements HttpClientResponse {}

class _MockHttpHeaders extends Mock implements HttpHeaders {}

HttpClient _createHttpClient() {
HttpClient _createHttpClient({required List<int> data}) {
final client = _MockHttpClient();
final request = _MockHttpClientRequest();
final response = _MockHttpClientResponse();
Expand All @@ -79,7 +82,7 @@ HttpClient _createHttpClient() {
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])
return Stream<List<int>>.fromIterable(<List<int>>[data])
.listen(onData, onDone: onDone);
});
when(() => request.headers).thenReturn(headers);
Expand Down
2 changes: 1 addition & 1 deletion packages/mocktail_image_network/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <int>[];

response.listen(data.addAll);

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

expect(data, equals(greenPixel));
},
imageBytes: greenPixel,
);
});
});
}

0 comments on commit df3f363

Please sign in to comment.