Skip to content

Commit 7caf0be

Browse files
committed
feat: add mock call for maybePop (thanks @korzonkiee!)
1 parent 54d1026 commit 7caf0be

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- feat: add `whereSettings`, `whereName`, `whereArguments`, `whereMaintainState` and `whereFullscreenDialog` matcher arguments to `isRoute` matcher
44
- **DEPRECATE**: fix: `named` argument on `isRoute` deprecated in favor of `whereName`
5+
- feat: add mock call for `maybePop` (thanks [@korzonkiee](https://github.com/korzonkiee)!)
56

67
# 0.1.1
78

lib/src/mock_navigator.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ class _MockNavigatorState extends NavigatorState {
145145
return _navigator.popUntil(predicate);
146146
}
147147

148+
@override
149+
Future<bool> maybePop<T extends Object?>([T? result]) {
150+
return _navigator.maybePop<T>(result);
151+
}
152+
148153
@override
149154
Future<T?> pushAndRemoveUntil<T extends Object?>(
150155
Route<T> newRoute,

test/src/mock_navigator_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,22 @@ void main() {
186186
verify(() => navigator.popUntil(testRoutePredicate)).called(1);
187187
});
188188

189+
testWidgets('mocks .maybePop calls', (tester) async {
190+
when(() => navigator.maybePop(any<dynamic>()))
191+
.thenAnswer((_) async => true);
192+
193+
await tester.pumpTest(
194+
navigator: navigator,
195+
builder: (context) => TextButton(
196+
onPressed: () => Navigator.of(context).maybePop(testRoutePredicate),
197+
child: const Text('Trigger'),
198+
),
199+
);
200+
201+
await tester.tap(find.byType(TextButton));
202+
verify(() => navigator.maybePop(testRoutePredicate)).called(1);
203+
});
204+
189205
testWidgets('mocks .pushAndRemoveUntil calls', (tester) async {
190206
when(() => navigator.pushAndRemoveUntil(any(), any()))
191207
.thenAnswer((_) async {});

0 commit comments

Comments
 (0)