MCPcopy
hub / github.com/TanStack/router / setupBeforeLoadNotFoundHierarchy

Function setupBeforeLoadNotFoundHierarchy

packages/router-core/tests/load.test.ts:866–951  ·  view source on GitHub ↗
(throwAtIndex: 1 | 2 | 3)

Source from the content-addressed store, hash-verified

864
865describe('head execution', () => {
866 const setupBeforeLoadNotFoundHierarchy = (throwAtIndex: 1 | 2 | 3) => {
867 const loaderResolvers: Array<(() => void) | undefined> = []
868
869 const makeLoader = (index: number) =>
870 vi.fn(async () => {
871 await new Promise<void>((resolve) => {
872 loaderResolvers[index] = resolve
873 })
874 return { level: index }
875 })
876
877 const makeHead = (label: string) =>
878 vi.fn(() => ({ meta: [{ title: label }] }))
879
880 const rootRoute = new BaseRootRoute({
881 loader: makeLoader(0),
882 head: makeHead('Root'),
883 })
884
885 const level1Route = new BaseRoute({
886 getParentRoute: () => rootRoute,
887 path: '/level-1',
888 loader: makeLoader(1),
889 head: makeHead('Level 1'),
890 beforeLoad:
891 throwAtIndex === 1
892 ? () => {
893 throw notFound()
894 }
895 : undefined,
896 })
897
898 const level2Route = new BaseRoute({
899 getParentRoute: () => level1Route,
900 path: '/level-2',
901 loader: makeLoader(2),
902 head: makeHead('Level 2'),
903 beforeLoad:
904 throwAtIndex === 2
905 ? () => {
906 throw notFound()
907 }
908 : undefined,
909 })
910
911 const level3Route = new BaseRoute({
912 getParentRoute: () => level2Route,
913 path: '/level-3',
914 loader: makeLoader(3),
915 head: makeHead('Level 3'),
916 beforeLoad:
917 throwAtIndex === 3
918 ? () => {
919 throw notFound()
920 }
921 : undefined,
922 })
923

Callers 1

Calls 4

notFoundFunction · 0.90
createMemoryHistoryFunction · 0.90
makeLoaderFunction · 0.85
makeHeadFunction · 0.85

Tested by

no test coverage detected