Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.

Commit c3241ce

Browse files
chore: prepare for transfer (#7)
* chore: prepare for transfer * add @orestesgaolin as CODEOWNER * feat: add matchers and example project also fixed ci config and bumped version * remove unnecessary imports * fix pana score by settings repo link to current repo * partially implement feedback from @felangel * refactor: use mocktail and simplify API (#8) Co-authored-by: Felix Angelov <felangelov@gmail.com>
1 parent 5bd22d7 commit c3241ce

95 files changed

Lines changed: 2664 additions & 65 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Every request must be reviewed and accepted by:
2+
3+
* @jeroen-meijer @felangel @orestesgaolin
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
---
5+
6+
**Describe the bug**
7+
A clear and concise description of what the bug is.
8+
9+
**To Reproduce**
10+
Steps to reproduce the behavior:
11+
12+
1. Go to '...'
13+
2. Click on '....'
14+
3. Scroll down to '....'
15+
4. See error
16+
17+
**Expected behavior**
18+
A clear and concise description of what you expected to happen.
19+
20+
**Screenshots**
21+
If applicable, add screenshots to help explain your problem.
22+
23+
**Additional context**
24+
Add any other context about the problem here.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
---
5+
6+
**Is your feature request related to a problem? Please describe.**
7+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
8+
9+
**Describe the solution you'd like**
10+
A clear and concise description of what you want to happen.
11+
12+
**Describe alternatives you've considered**
13+
A clear and concise description of any alternative solutions or features you've considered.
14+
15+
**Additional context**
16+
Add any other context or screenshots about the feature request here.

.github/pull_request_template.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
Thanks for contributing!
3+
4+
Provide a description of your changes below and a general summary in the title
5+
6+
Please look at the following checklist to ensure that your PR can be accepted quickly:
7+
-->
8+
9+
## Description
10+
11+
<!--- Describe your changes in detail -->
12+
13+
## Type of Change
14+
15+
<!--- Put an `x` in all the boxes that apply: -->
16+
17+
- [ ] ✨ New feature (non-breaking change which adds functionality)
18+
- [ ] 🛠️ Bug fix (non-breaking change which fixes an issue)
19+
- [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change)
20+
- [ ] 🧹 Code refactor
21+
- [ ] ✅ Build configuration change
22+
- [ ] 📝 Documentation
23+
- [ ] 🗑️ Chore

.github/workflows/main.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: mockingjay
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: subosito/flutter-action@v1.5.0
12+
13+
- name: Install Dependencies
14+
run: flutter packages get
15+
16+
- name: Format
17+
run: flutter format --set-exit-if-changed .
18+
19+
- name: Analyze
20+
run: flutter analyze lib test example
21+
22+
- name: Run tests
23+
run: flutter test --no-pub --coverage --test-randomize-ordering-seed random
24+
25+
- name: Run example project tests
26+
working-directory: example/
27+
run: flutter test --no-pub --test-randomize-ordering-seed random
28+
29+
- name: Check Code Coverage
30+
uses: VeryGoodOpenSource/very_good_coverage@v1.1.1
31+
with:
32+
path: coverage/lcov.info
33+
34+
- name: Upload coverage to Codecov
35+
uses: codecov/codecov-action@v1
36+
with:
37+
token: ${{ secrets.CODECOV_TOKEN }}
38+
39+
pana:
40+
runs-on: ubuntu-latest
41+
42+
steps:
43+
- uses: actions/checkout@v2.3.4
44+
- uses: subosito/flutter-action@v1.5.0
45+
46+
- name: Install Dependencies
47+
run: |
48+
flutter packages get
49+
flutter pub global activate pana
50+
51+
- name: Verify Pub Score
52+
run: ./tool/verify_pub_score.sh

.gitignore

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Miscellaneous
22
*.class
3+
*.lock
34
*.log
45
*.pyc
56
*.swp
@@ -15,11 +16,29 @@
1516
*.iws
1617
.idea/
1718

18-
# The .vscode folder contains launch configuration and tasks you configure in
19-
# VS Code which you may wish to be included in version control, so this line
20-
# is commented out by default.
21-
# .vscode/
22-
.vscode/settings.json
19+
# Visual Studio Code related
20+
.classpath
21+
.project
22+
.settings/
23+
.vscode/
24+
25+
# Flutter repo-specific
26+
/bin/cache/
27+
/bin/mingit/
28+
/dev/benchmarks/mega_gallery/
29+
/dev/bots/.recipe_deps
30+
/dev/bots/android_tools/
31+
/dev/docs/doc/
32+
/dev/docs/flutter.docs.zip
33+
/dev/docs/lib/
34+
/dev/docs/pubspec.yaml
35+
/dev/integration_tests/**/xcuserdata
36+
/dev/integration_tests/**/Pods
37+
/packages/flutter/coverage/
38+
version
39+
40+
# packages file containing multi-root paths
41+
.packages.generated
2342

2443
# Flutter/Dart/Pub related
2544
**/doc/api/
@@ -30,7 +49,10 @@
3049
.pub-cache/
3150
.pub/
3251
build/
33-
pubspec.lock
52+
flutter_*.png
53+
linked_*.ds
54+
unlinked.ds
55+
unlinked_spec.ds
3456

3557
# Android related
3658
**/android/**/gradle-wrapper.jar
@@ -40,6 +62,8 @@ pubspec.lock
4062
**/android/gradlew.bat
4163
**/android/local.properties
4264
**/android/**/GeneratedPluginRegistrant.java
65+
**/android/key.properties
66+
*.jks
4367

4468
# iOS/XCode related
4569
**/ios/**/*.mode1v3
@@ -69,11 +93,17 @@ pubspec.lock
6993
**/ios/ServiceDefinitions.json
7094
**/ios/Runner/GeneratedPluginRegistrant.*
7195

72-
# Test related
73-
coverage
96+
# Coverage
97+
coverage/
98+
coverage_badge.svg
99+
.test_coverage.dart
100+
*.lcov
101+
nohup.out
74102

75103
# Exceptions to above rules.
76104
!**/ios/**/default.mode1v3
77105
!**/ios/**/default.mode2v3
78106
!**/ios/**/default.pbxuser
79-
!**/ios/**/default.perspectivev3
107+
!**/ios/**/default.perspectivev3
108+
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
109+
!/dev/ci/**/Gemfile.lock

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## [0.0.1] - TODO: Add release date.
1+
# 0.1.0
22

3-
* TODO: Describe initial release.
3+
- feat: initial alpha release

LICENSE

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
TODO: Add your license here.
1+
MIT License
2+
3+
Copyright (c) 2021 Very Good Ventures
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,76 @@
1-
# mock_navigator
1+
# 🕊 mockingjay
22

3-
An experimental package that attempts to make it easy to mock Flutter's navigator routes.
3+
[![Very Good Ventures](https://raw.githubusercontent.com/VeryGoodOpenSource/mockingjay/main/assets/vgv_logo.png)](https://verygood.ventures)
4+
5+
Developed with 💙 by [Very Good Ventures](https://verygood.ventures) 🦄
6+
7+
[![ci](https://github.com/jeroen-meijer/mockingjay/workflows/ci/badge.svg)](https://github.com/jeroen-meijer/mockingjay/actions)
8+
[![pub package](https://img.shields.io/pub/v/mockingjay.svg)](https://pub.dartlang.org/packages/mockingjay)
9+
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
10+
[![style: very good analysis][badge]][badge_link]
11+
12+
---
13+
14+
A package that makes it easy to mock, test and verify navigation calls in Flutter. It works in tandem with [`mocktail`][mocktail], allowing you to mock a navigator the same way you would any other object, making it easier to test navigation behavior independently from the UI it's supposed to render.
415

516
## Usage
617

7-
TODO
18+
To use the package in your tests, add it to your dev dependencies in your `pubspec.yaml`:
19+
20+
```yaml
21+
dev_dependencies:
22+
mockingjay: ^0.1.0
23+
```
24+
25+
Then, in your tests, create a `MockNavigator` class like so:
26+
27+
```dart
28+
import 'package:mockingjay/mockingjay.dart';
29+
30+
final navigator = MockNavigator();
31+
```
32+
33+
Now you can create a new `MockNavigator` and pass it to a `MockNavigatorProvider`.
34+
35+
Any widget looking up the nearest `Navigator.of(context)` from that point will now receive the `MockNavigator`, allowing you to mock (using `when`) and `verify` any navigation calls. Use the included matchers to more easily match specific route names and types.
36+
37+
**Note**: make sure the `MockNavigatorProvider` is constructed **below** the `MaterialApp`. Otherwise, any `Navigator.of(context)` call will return a real `NavigatorState` instead of the mock.
38+
39+
```dart
40+
void main() {
41+
late MockNavigator navigator;
42+
43+
setUp(() {
44+
navigator = MockNavigator();
45+
when(() => navigator.push(any())).thenAnswer((_) async => null);
46+
});
847
9-
## Getting Started
48+
group('MyButton', () {
49+
testWidgets(
50+
'pushes a new screen when button is pressed',
51+
(tester) async {
52+
await tester.pumpWidget(
53+
MaterialApp(
54+
home: MockNavigatorProvider(
55+
navigator: navigator,
56+
child: Scaffold(
57+
body: MyButton(),
58+
),
59+
),
60+
),
61+
);
1062
11-
This project is a starting point for a Dart
12-
[package](https://flutter.dev/developing-packages/),
13-
a library module containing code that can be shared easily across
14-
multiple Flutter or Dart projects.
63+
await tester.tap(find.byType(MyButton));
64+
verify(
65+
() => navigator.push(any(that: isRoute<void>(named: '/second_screen'))),
66+
).called(1);
67+
},
68+
);
69+
});
70+
}
71+
```
1572

16-
For help getting started with Flutter, view our
17-
[online documentation](https://flutter.dev/docs), which offers tutorials,
18-
samples, guidance on mobile development, and a full API reference.
73+
[very good analysis]: https://github.com/VeryGoodOpenSource/very_good_analysis
74+
[badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg
75+
[badge_link]: https://pub.dev/packages/mockingjay
76+
[mocktail]: https://pub.dev/packages/mocktail

assets/vgv_logo.png

11.9 KB
Loading

0 commit comments

Comments
 (0)