diff --git a/.github/workflows/example.yaml b/.github/workflows/example.yaml index 935c4e4..957cef7 100644 --- a/.github/workflows/example.yaml +++ b/.github/workflows/example.yaml @@ -20,5 +20,6 @@ jobs: uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1 with: flutter_channel: stable + flutter_version: "3.32.0" working_directory: example runs_on: macos-latest diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 88937e7..e47b1c8 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -22,7 +22,7 @@ jobs: flutter-version: # The version of Flutter to use should use the minimum Dart SDK version supported by the package, # refer to https://docs.flutter.dev/development/tools/sdk/releases. - - "3.29.0" + - "3.32.0" - "3.x" uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1 with: diff --git a/analysis_options.yaml b/analysis_options.yaml index c2f4cbb..9df80aa 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1 +1 @@ -include: package:very_good_analysis/analysis_options.7.0.0.yaml +include: package:very_good_analysis/analysis_options.yaml diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml index c59316b..ce42cd4 100644 --- a/example/analysis_options.yaml +++ b/example/analysis_options.yaml @@ -1,4 +1,4 @@ -include: package:very_good_analysis/analysis_options.7.0.0.yaml +include: package:very_good_analysis/analysis_options.yaml linter: rules: public_member_api_docs: false diff --git a/example/pubspec.yaml b/example/pubspec.yaml index f60fa9d..f6c8473 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -4,14 +4,15 @@ version: 0.0.1 homepage: https://github.com/VeryGoodOpenSource/mockingjay environment: - sdk: ^3.7.0 + sdk: ^3.8.0 + flutter: ^3.32.0 dependencies: bloc: ^9.0.0 - equatable: ^2.0.5 + equatable: ^2.0.7 flutter: sdk: flutter - flutter_bloc: ^9.1.0 + flutter_bloc: ^9.1.1 universal_io: ^2.2.2 dev_dependencies: @@ -21,7 +22,7 @@ dev_dependencies: mockingjay: path: ../ mocktail: ^1.0.4 - very_good_analysis: ^7.0.0 + very_good_analysis: ^8.0.0 flutter: uses-material-design: true diff --git a/lib/src/matchers.dart b/lib/src/matchers.dart index 109e318..a114a73 100644 --- a/lib/src/matchers.dart +++ b/lib/src/matchers.dart @@ -284,27 +284,25 @@ class _RouteMatcher extends Matcher { mismatchDescriptions.add("the route's `arguments` $mismatch"); } if (!maintainStateMatches) { - final mismatch = - item is! ModalRoute - ? 'is not a property on `${item.runtimeType}` and can only be ' - 'used with `ModalRoute`s' - : whereMaintainState!.describeMismatchAsString( - item.maintainState, - matchState, - verbose: verbose, - ); + final mismatch = item is! ModalRoute + ? 'is not a property on `${item.runtimeType}` and can only be ' + 'used with `ModalRoute`s' + : whereMaintainState!.describeMismatchAsString( + item.maintainState, + matchState, + verbose: verbose, + ); mismatchDescriptions.add('`maintainState` $mismatch'); } if (!fullscreenDialogMatches) { - final mismatch = - item is! PageRoute - ? 'is not a property on `${item.runtimeType}` and can only be ' - 'used with `PageRoute`s' - : whereFullscreenDialog!.describeMismatchAsString( - item.fullscreenDialog, - matchState, - verbose: verbose, - ); + final mismatch = item is! PageRoute + ? 'is not a property on `${item.runtimeType}` and can only be ' + 'used with `PageRoute`s' + : whereFullscreenDialog!.describeMismatchAsString( + item.fullscreenDialog, + matchState, + verbose: verbose, + ); mismatchDescriptions.add('`fullscreenDialog` $mismatch'); } diff --git a/lib/src/mock_navigator.dart b/lib/src/mock_navigator.dart index 6b70650..fd67021 100644 --- a/lib/src/mock_navigator.dart +++ b/lib/src/mock_navigator.dart @@ -319,7 +319,12 @@ class _MockNavigatorState extends NavigatorState { } @override - void removeRouteBelow(Route anchorRoute) { - return _navigator.removeRouteBelow(anchorRoute); + void removeRoute(Route route, [T? result]) { + return _navigator.removeRoute(route, result); + } + + @override + void removeRouteBelow(Route anchorRoute, [T? result]) { + return _navigator.removeRouteBelow(anchorRoute, result); } } diff --git a/pubspec.yaml b/pubspec.yaml index dd6b936..8c57f82 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,17 +4,17 @@ version: 1.0.0 homepage: https://github.com/VeryGoodOpenSource/mockingjay environment: - sdk: ^3.7.0 - flutter: ^3.29.0 + sdk: ^3.8.0 + flutter: ^3.32.0 dependencies: flutter: sdk: flutter flutter_test: sdk: flutter - matcher: ^0.12.16+1 + matcher: ^0.12.17 mocktail: ^1.0.4 test: ^1.25.7 dev_dependencies: - very_good_analysis: ^7.0.0 + very_good_analysis: ^8.0.0 diff --git a/test/src/mock_navigator_test.dart b/test/src/mock_navigator_test.dart index 755dd40..0e58eb1 100644 --- a/test/src/mock_navigator_test.dart +++ b/test/src/mock_navigator_test.dart @@ -53,11 +53,10 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: () => Navigator.of(context).push(testRoute), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of(context).push(testRoute), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -69,11 +68,10 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: () => Navigator.of(context).pushNamed(testRouteName), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of(context).pushNamed(testRouteName), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -87,14 +85,12 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => Navigator.of( - context, - ).pushNamedAndRemoveUntil(testRouteName, testRoutePredicate), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of( + context, + ).pushNamedAndRemoveUntil(testRouteName, testRoutePredicate), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -113,11 +109,10 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: () => Navigator.of(context).pushReplacement(testRoute), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of(context).pushReplacement(testRoute), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -131,13 +126,11 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => - Navigator.of(context).pushReplacementNamed(testRouteName), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => + Navigator.of(context).pushReplacementNamed(testRouteName), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -149,11 +142,10 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: () => Navigator.of(context).pop(testRoute), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of(context).pop(testRoute), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -167,12 +159,10 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => Navigator.of(context).popAndPushNamed(testRouteName), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of(context).popAndPushNamed(testRouteName), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -184,12 +174,10 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => Navigator.of(context).popUntil(testRoutePredicate), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of(context).popUntil(testRoutePredicate), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -201,11 +189,10 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: () => Navigator.of(context).canPop(), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of(context).canPop(), + child: const Text('Trigger'), + ), ); // Called by NavigatorState.didChangeDependencies initially @@ -219,11 +206,10 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: () => Navigator.of(context).maybePop(), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of(context).maybePop(), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -237,11 +223,10 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: () => Navigator.of(context).maybePop(true), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of(context).maybePop(true), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -255,14 +240,12 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => Navigator.of( - context, - ).pushAndRemoveUntil(testRoute, testRoutePredicate), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of( + context, + ).pushAndRemoveUntil(testRoute, testRoutePredicate), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -278,14 +261,11 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => Navigator.of( - context, - ).restorablePopAndPushNamed(testRouteName), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => + Navigator.of(context).restorablePopAndPushNamed(testRouteName), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -301,14 +281,11 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => Navigator.of( - context, - ).restorablePush(restorableTestRouteBuilder), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => + Navigator.of(context).restorablePush(restorableTestRouteBuilder), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -324,15 +301,13 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => Navigator.of(context).restorablePushAndRemoveUntil( - restorableTestRouteBuilder, - testRoutePredicate, - ), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of(context).restorablePushAndRemoveUntil( + restorableTestRouteBuilder, + testRoutePredicate, + ), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -351,13 +326,11 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => - Navigator.of(context).restorablePushNamed(testRouteName), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => + Navigator.of(context).restorablePushNamed(testRouteName), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -373,15 +346,14 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => Navigator.of(context).restorablePushNamedAndRemoveUntil( - testRouteName, - testRoutePredicate, - ), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => + Navigator.of(context).restorablePushNamedAndRemoveUntil( + testRouteName, + testRoutePredicate, + ), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -400,14 +372,12 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => Navigator.of( - context, - ).restorablePushReplacement(restorableTestRouteBuilder), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of( + context, + ).restorablePushReplacement(restorableTestRouteBuilder), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -423,14 +393,12 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => Navigator.of( - context, - ).restorablePushReplacementNamed(testRouteName), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of( + context, + ).restorablePushReplacementNamed(testRouteName), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -449,15 +417,13 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => Navigator.of(context).restorableReplace( - oldRoute: testRoute, - newRouteBuilder: restorableTestRouteBuilder, - ), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of(context).restorableReplace( + oldRoute: testRoute, + newRouteBuilder: restorableTestRouteBuilder, + ), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -479,15 +445,13 @@ void main() { await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => Navigator.of(context).restorableReplaceRouteBelow( - anchorRoute: testRoute, - newRouteBuilder: restorableTestRouteBuilder, - ), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of(context).restorableReplaceRouteBelow( + anchorRoute: testRoute, + newRouteBuilder: restorableTestRouteBuilder, + ), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton)); @@ -499,17 +463,35 @@ void main() { ).called(1); }); + testWidgets('mocks .removeRoute calls', (tester) async { + when( + () => navigator.removeRoute(any(), any()), + ).thenAnswer((_) {}); + + await tester.pumpTest( + navigator: navigator, + builder: (context) => TextButton( + onPressed: () => Navigator.of(context).removeRoute(testRoute), + child: const Text('Trigger'), + ), + ); + + await tester.tap(find.byType(TextButton)); + + verify(() => navigator.removeRoute(testRoute)).called(1); + }); + testWidgets('mocks .removeRouteBelow calls', (tester) async { - when(() => navigator.removeRouteBelow(any())).thenAnswer((_) {}); + when( + () => navigator.removeRouteBelow(any(), any()), + ).thenAnswer((_) {}); await tester.pumpTest( navigator: navigator, - builder: - (context) => TextButton( - onPressed: - () => Navigator.of(context).removeRouteBelow(testRoute), - child: const Text('Trigger'), - ), + builder: (context) => TextButton( + onPressed: () => Navigator.of(context).removeRouteBelow(testRoute), + child: const Text('Trigger'), + ), ); await tester.tap(find.byType(TextButton));