Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
✅ Write a test for replace
  • Loading branch information
ValentinVignal committed Jul 5, 2022
commit 1db90bdf70ebebb56f64efc6c0fb76c4f16fc8d8
46 changes: 46 additions & 0 deletions packages/go_router/test/go_router_delegate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,52 @@ void main() {
);
});

group('replace', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider adding a test for replaceNamed too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test for replaceNamed in 44e35ef Tell me what you think about it

testWidgets(
'It should replace the last match with the given one',
(WidgetTester tester) async {
final GoRouter goRouter = GoRouter(
initialLocation: '/',
routes: <GoRoute>[
GoRoute(path: '/', builder: (_, __) => const SizedBox()),
GoRoute(path: '/page-0', builder: (_, __) => const SizedBox()),
GoRoute(path: '/page-1', builder: (_, __) => const SizedBox()),
],
);
await tester.pumpWidget(
MaterialApp.router(
routeInformationProvider: goRouter.routeInformationProvider,
routeInformationParser: goRouter.routeInformationParser,
routerDelegate: goRouter.routerDelegate,
),
);

goRouter.push('/page-0');

goRouter.routerDelegate.addListener(expectAsync0(() {}));
final GoRouteMatch first = goRouter.routerDelegate.matches.first;
final GoRouteMatch last = goRouter.routerDelegate.matches.last;
goRouter.replace('/page-1');
expect(goRouter.routerDelegate.matches.length, 2);
expect(
goRouter.routerDelegate.matches.first,
first,
reason: 'The first match should still be in the list of matches',
);
expect(
goRouter.routerDelegate.matches.last,
isNot(last),
reason: 'The last match should have been removed',
);
expect(
goRouter.routerDelegate.matches.last.fullpath,
'/page-1',
reason: 'The new location should have been pushed',
);
},
);
});

testWidgets('dispose unsubscribes from refreshListenable',
(WidgetTester tester) async {
final FakeRefreshListenable refreshListenable = FakeRefreshListenable();
Expand Down