mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] router: properly react on hashchange
Before this commit, hashchanges were not taken into account by the router, if used in history mode. Also, it's stupid, but i ran prettier on the codebase
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Destination, RouterEnv, Route } from "../../src/router/Router";
|
||||
import { makeTestEnv } from "../helpers";
|
||||
import { makeTestEnv, nextTick } from "../helpers";
|
||||
import { TestRouter } from "./TestRouter";
|
||||
|
||||
let env: RouterEnv;
|
||||
@@ -37,6 +37,21 @@ describe("router miscellaneous", () => {
|
||||
expect(window.location.pathname).toBe("/users/5");
|
||||
expect(env.qweb.forceUpdate).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
test("changing url to same route but with different params should trigger update (hash mode)", async () => {
|
||||
env.qweb.forceUpdate = jest.fn();
|
||||
router = new TestRouter(env, [{ name: "users", path: "/users/{{id}}" }], { mode: "hash" });
|
||||
await router.start();
|
||||
await router.navigate({ to: "users", params: { id: 3 } });
|
||||
expect(window.location.hash).toBe("#/users/3");
|
||||
expect(env.qweb.forceUpdate).toHaveBeenCalledTimes(1);
|
||||
|
||||
window.location.hash = "/users/5";
|
||||
window.dispatchEvent(new Event("hashchange"));
|
||||
await nextTick();
|
||||
expect(window.location.hash).toBe("#/users/5");
|
||||
expect(env.qweb.forceUpdate).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("routeToPath", () => {
|
||||
|
||||
Reference in New Issue
Block a user