Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:very_good_analysis/analysis_options.6.0.0.yaml
include: package:very_good_analysis/analysis_options.7.0.0.yaml
2 changes: 1 addition & 1 deletion lib/mockingjay.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// A package that makes it easy to mock, test and verify
/// navigation calls in Flutter.
library mockingjay;
library;

export 'package:mocktail/mocktail.dart';

Expand Down
16 changes: 7 additions & 9 deletions lib/src/matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ Matcher isRoute<T extends Object?>({
/// Returns a matcher that matches the [RouteSettings] from the given [route].
Matcher equalsSettingsOf(Route<dynamic> route) {
return isA<RouteSettings>()
.having(
(s) => s.name,
'name',
equals(route.settings.name),
)
.having((s) => s.name, 'name', equals(route.settings.name))
.having(
(s) => s.arguments,
'arguments',
Expand Down Expand Up @@ -87,8 +83,8 @@ class _RouteMatcher<T> extends Matcher {
hasMaintainStateMatcher ||
hasFullscreenDialogMatcher;

/// Takes an [input] string that looks like "FooBarRoute<MyType>" and extracts
/// the part "MyType".
/// Takes an [input] string that looks like `FooBarRoute<MyType>` and extracts
/// the part `MyType`.
///
/// If the `Route<` part cannot be found, it returns the input string
/// unchaged.
Expand Down Expand Up @@ -192,8 +188,10 @@ class _RouteMatcher<T> extends Matcher {
whereMaintainState!.matches(item.maintainState, matchState));
final fullscreenDialogMatches = !hasFullscreenDialogMatcher ||
(item is PageRoute &&
whereFullscreenDialog!
.matches(item.fullscreenDialog, matchState));
whereFullscreenDialog!.matches(
item.fullscreenDialog,
matchState,
));

return typeMatches &&
settingsMatches &&
Expand Down
2 changes: 1 addition & 1 deletion lib/src/mock_navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class _MockMaterialPageRoute extends MaterialPageRoute<void> {
// By the time the setState is called, the attribute is already set
// so we just ignore the error and the hack will do its job.
state.insert(entry);
} catch (_) {}
} on Object catch (_) {}
// Set mounted back to false to make sure the state doesn't get
// marked as dirty during OverlayEntry.remove().
state._mounted = false;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ dependencies:
test: ^1.25.7

dev_dependencies:
very_good_analysis: ^6.0.0
very_good_analysis: ^7.0.0
173 changes: 81 additions & 92 deletions test/src/matchers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ void main() {
bool fullscreenDialog = false,
}) {
return MaterialPageRoute<T>(
settings: RouteSettings(
name: name,
arguments: arguments,
),
settings: RouteSettings(name: name, arguments: arguments),
maintainState: maintainState,
fullscreenDialog: fullscreenDialog,
builder: (_) => const SizedBox(),
Expand All @@ -49,19 +46,17 @@ void main() {

group('constructor', () {
test(
'throws AssertionError when both whereSettings '
'and whereName or whereArguments matchers are provided',
() {
expect(
() => isRoute(
whereSettings: isNotNull,
whereName: isNotNull,
whereArguments: isNotNull,
),
throwsAssertionError,
);
},
);
'throws AssertionError when both whereSettings '
'and whereName or whereArguments matchers are provided', () {
expect(
() => isRoute(
whereSettings: isNotNull,
whereName: isNotNull,
whereArguments: isNotNull,
),
throwsAssertionError,
);
});
});

group('without arguments', () {
Expand Down Expand Up @@ -130,43 +125,44 @@ void main() {
expect(
createRoute<dynamic>(name: '/test'),
isRoute(
whereSettings:
isA<RouteSettings>().having((s) => s.name, 'name', '/test'),
whereSettings: isA<RouteSettings>().having(
(s) => s.name,
'name',
'/test',
),
),
);
});

test(
'does not match anything that is not a route '
'with matching settings',
() {
expectToFail(
createRoute<dynamic>(name: '/test'),
isRoute(whereSettings: equalsSettingsOf(createRoute<String>())),
withMessage:
"is a route where `settings` has `name` with value '/test'",
);
expectToFail(
createRoute<dynamic>(name: '/other_name'),
isRoute(
whereSettings: equalsSettingsOf(
createRoute<dynamic>(name: '/test'),
),
'does not match anything that is not a route '
'with matching settings', () {
expectToFail(
createRoute<dynamic>(name: '/test'),
isRoute(whereSettings: equalsSettingsOf(createRoute<String>())),
withMessage:
"is a route where `settings` has `name` with value '/test'",
);
expectToFail(
createRoute<dynamic>(name: '/other_name'),
isRoute(
whereSettings: equalsSettingsOf(
createRoute<dynamic>(name: '/test'),
),
withMessage: '''
),
withMessage: '''
is a route where `settings` has `name` with value '/other_name' which is different.
Expected: /test
Actual: /other_name ...
^
Differ at offset 1''',
);
expectToFail(
1,
isRoute(whereSettings: equalsSettingsOf(createRoute<dynamic>())),
withMessage: 'is not a route but an instance of `int`',
);
},
);
);
expectToFail(
1,
isRoute(whereSettings: equalsSettingsOf(createRoute<dynamic>())),
withMessage: 'is not a route but an instance of `int`',
);
});
});

group('with whereName argument', () {
Expand Down Expand Up @@ -244,36 +240,31 @@ is a route where the route's `name` is different.

group('with whereMaintainState argument', () {
test('matches any route with matching maintainState argument', () {
expect(
expect(createRoute<dynamic>(), isRoute(whereMaintainState: isTrue));
});

test(
'does not match anything that is not a route with matching '
'maintainState argument', () {
expectToFail(
createRoute<dynamic>(),
isRoute(whereMaintainState: isFalse),
withMessage: 'is a route where `maintainState` '
'is true instead of false',
);
expectToFail(
NonModalRoute(),
isRoute(whereMaintainState: isTrue),
withMessage: 'is a route where `maintainState` '
'is not a property on `NonModalRoute` and can only be used '
'with `ModalRoute`s',
);
expectToFail(
1,
isRoute(whereMaintainState: isTrue),
withMessage: 'is not a route but an instance of `int`',
);
});

test(
'does not match anything that is not a route with matching '
'maintainState argument',
() {
expectToFail(
createRoute<dynamic>(),
isRoute(whereMaintainState: isFalse),
withMessage: 'is a route where `maintainState` '
'is true instead of false',
);
expectToFail(
NonModalRoute(),
isRoute(whereMaintainState: isTrue),
withMessage: 'is a route where `maintainState` '
'is not a property on `NonModalRoute` and can only be used '
'with `ModalRoute`s',
);
expectToFail(
1,
isRoute(whereMaintainState: isTrue),
withMessage: 'is not a route but an instance of `int`',
);
},
);
});

group('with whereFullscreenDialog argument', () {
Expand All @@ -285,29 +276,27 @@ is a route where the route's `name` is different.
});

test(
'does not match anything that is not a route with matching '
'fullscreenDialog argument',
() {
expectToFail(
createRoute<dynamic>(fullscreenDialog: true),
isRoute(whereFullscreenDialog: isFalse),
withMessage: 'is a route where `fullscreenDialog` '
'is true instead of false',
);
expectToFail(
NonModalRoute(),
isRoute(whereFullscreenDialog: isFalse),
withMessage: 'is a route where `fullscreenDialog` '
'is not a property on `NonModalRoute` and can only be used '
'with `PageRoute`s',
);
expectToFail(
1,
isRoute(whereFullscreenDialog: isTrue),
withMessage: 'is not a route but an instance of `int`',
);
},
);
'does not match anything that is not a route with matching '
'fullscreenDialog argument', () {
expectToFail(
createRoute<dynamic>(fullscreenDialog: true),
isRoute(whereFullscreenDialog: isFalse),
withMessage: 'is a route where `fullscreenDialog` '
'is true instead of false',
);
expectToFail(
NonModalRoute(),
isRoute(whereFullscreenDialog: isFalse),
withMessage: 'is a route where `fullscreenDialog` '
'is not a property on `NonModalRoute` and can only be used '
'with `PageRoute`s',
);
expectToFail(
1,
isRoute(whereFullscreenDialog: isTrue),
withMessage: 'is not a route but an instance of `int`',
);
});
});

test('returns all relevant mismatches in one log', () {
Expand Down