Skip to content

Commit

Permalink
Unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Aug 11, 2023
1 parent 0a701a3 commit d6176ed
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
39 changes: 39 additions & 0 deletions packages/router/__tests__/router-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13731,6 +13731,45 @@ describe("a router", () => {
);
consoleWarn.mockReset();
});

it("handles errors thrown from static loaders before lazy has completed", async () => {
let consoleWarn = jest.spyOn(console, "warn");
let t = setup({
routes: [
{
id: "root",
path: "/",
children: [
{
id: "lazy",
path: "lazy",
loader: true,
lazy: true,
},
],
},
],
});

let A = await t.navigate("/lazy");

await A.loaders.lazy.reject("STATIC LOADER ERROR");
expect(t.router.state.navigation.state).toBe("loading");

// We shouldn't bubble the loader error until after this resolves
// so we know if it has a boundary or not
await A.lazy.lazy.resolve({
hasErrorBoundary: true,
});
expect(t.router.state.location.pathname).toBe("/lazy");
expect(t.router.state.navigation.state).toBe("idle");
expect(t.router.state.loaderData).toEqual({});
expect(t.router.state.errors).toEqual({
lazy: "STATIC LOADER ERROR",
});

consoleWarn.mockReset();
});
});

describe("interruptions", () => {
Expand Down
1 change: 0 additions & 1 deletion packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3645,7 +3645,6 @@ async function callLoaderOrAction(
// Run statically defined handler in parallel with lazy()
let handlerError;
let values = await Promise.all([
// TODO: Write test for this
// If the handler throws, don't let it immediately bubble out,
// since we need to let the lazy() execution finish so we know if this
// route has a boundary that can handle the error
Expand Down

0 comments on commit d6176ed

Please sign in to comment.