[FIX] router: properly redirect if necessary when started

This commit is contained in:
Géry Debongnie
2019-08-05 16:00:58 +02:00
parent 0a276fbf1d
commit 6cd5ec10f0
2 changed files with 24 additions and 2 deletions
+14
View File
@@ -161,4 +161,18 @@ describe("beforeRouteEnter", () => {
expect(window.location.pathname).toBe("/some/pathc");
expect(router.currentRouteName).toBe("routec");
});
test("navigation is initially redirected if guard decides so", async () => {
expect(window.location.pathname).toBe("/");
const guard = jest.fn(() => {return {to: "otherroute"}});
router = new TestRouter(env, [
{ name: "landing", path: "/", beforeRouteEnter: guard},
{ name: "otherroute", path: "/some/other/route"}
]);
expect(window.location.pathname).toBe("/");
await router.start();
expect(window.location.pathname).toBe("/some/other/route");
});
});