Skip to content

Commit 4b96510

Browse files
Add pathless fog of war test to fetchers unit tests (#13727)
1 parent 2352aaa commit 4b96510

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

packages/react-router/__tests__/router/fetchers-test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,50 @@ describe("fetchers", () => {
116116
expect(router._internalFetchControllers.size).toBe(0);
117117
});
118118

119+
it("unabstracted loader fetch with fog of war", async () => {
120+
let dfd = createDeferred();
121+
let router = createRouter({
122+
history: createMemoryHistory({ initialEntries: ["/"] }),
123+
routes: [
124+
{
125+
id: "root",
126+
// Note: No path is provided on the root route in this test to
127+
// ensure nothing matches before routes are patched
128+
},
129+
],
130+
hydrationData: {
131+
loaderData: { root: "ROOT DATA" },
132+
},
133+
async patchRoutesOnNavigation({ path, patch }) {
134+
if (path === "/lazy") {
135+
patch("root", [
136+
{
137+
id: "lazy",
138+
path: "/lazy",
139+
loader: () => dfd.promise,
140+
},
141+
]);
142+
}
143+
},
144+
});
145+
let fetcherData = getFetcherData(router);
146+
147+
let key = "key";
148+
router.fetch(key, "lazy", "/lazy");
149+
expect(router.getFetcher(key)).toEqual({
150+
state: "loading",
151+
formMethod: undefined,
152+
formEncType: undefined,
153+
formData: undefined,
154+
});
155+
156+
await dfd.resolve("DATA");
157+
expect(router.getFetcher(key)).toBe(IDLE_FETCHER);
158+
expect(fetcherData.get(key)).toBe("DATA");
159+
160+
expect(router._internalFetchControllers.size).toBe(0);
161+
});
162+
119163
it("loader fetch", async () => {
120164
let t = initializeTest({
121165
url: "/foo",

0 commit comments

Comments
 (0)