-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix URL creation with memory history (#9814)
* Fix URL creation with memory history * Create history-aware URLs * add changeset * Fix hash test
- Loading branch information
1 parent
ce2bb3f
commit b154367
Showing
11 changed files
with
184 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@remix-run/router": patch | ||
--- | ||
|
||
Fix URL creation with memory histories |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
|
||
import { createMemoryHistory, createRouter } from "../index"; | ||
|
||
// This suite of tests specifically runs in the node jest environment to catch | ||
// issues when window is not present | ||
describe("a memory router", () => { | ||
it("initializes properly", async () => { | ||
let router = createRouter({ | ||
routes: [ | ||
{ | ||
path: "/", | ||
}, | ||
], | ||
history: createMemoryHistory(), | ||
}); | ||
expect(router.state).toEqual({ | ||
historyAction: "POP", | ||
loaderData: {}, | ||
actionData: null, | ||
errors: null, | ||
location: { | ||
hash: "", | ||
key: expect.any(String), | ||
pathname: "/", | ||
search: "", | ||
state: null, | ||
}, | ||
matches: [ | ||
{ | ||
params: {}, | ||
pathname: "/", | ||
pathnameBase: "/", | ||
route: { | ||
id: "0", | ||
path: "/", | ||
}, | ||
}, | ||
], | ||
initialized: true, | ||
navigation: { | ||
location: undefined, | ||
state: "idle", | ||
}, | ||
preventScrollReset: false, | ||
restoreScrollPosition: null, | ||
revalidation: "idle", | ||
fetchers: new Map(), | ||
}); | ||
router.dispose(); | ||
}); | ||
|
||
it("can create Requests without window", async () => { | ||
let loaderSpy = jest.fn(); | ||
let router = createRouter({ | ||
routes: [ | ||
{ | ||
path: "/", | ||
}, | ||
{ | ||
path: "/a", | ||
loader: loaderSpy, | ||
}, | ||
], | ||
history: createMemoryHistory(), | ||
}); | ||
|
||
router.navigate("/a"); | ||
expect(loaderSpy.mock.calls[0][0].request.url).toBe("http://localhost/a"); | ||
router.dispose(); | ||
}); | ||
|
||
it("can create URLs without window", async () => { | ||
let shouldRevalidateSpy = jest.fn(); | ||
|
||
let router = createRouter({ | ||
routes: [ | ||
{ | ||
path: "/", | ||
loader: () => "ROOT", | ||
shouldRevalidate: shouldRevalidateSpy, | ||
children: [ | ||
{ | ||
index: true, | ||
}, | ||
{ | ||
path: "a", | ||
}, | ||
], | ||
}, | ||
], | ||
history: createMemoryHistory(), | ||
hydrationData: { loaderData: { "0": "ROOT" } }, | ||
}); | ||
|
||
router.navigate("/a"); | ||
expect(shouldRevalidateSpy.mock.calls[0][0].currentUrl.toString()).toBe( | ||
"http://localhost/" | ||
); | ||
expect(shouldRevalidateSpy.mock.calls[0][0].nextUrl.toString()).toBe( | ||
"http://localhost/a" | ||
); | ||
router.dispose(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.