Skip to content

Commit 446d797

Browse files
authored
test: cover Solid SSR route error rendering (#6854)
test: cover solid SSR route error rendering
1 parent 637f38c commit 446d797

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { renderToStringAsync } from 'solid-js/web'
3+
import {
4+
RouterProvider,
5+
createMemoryHistory,
6+
createRootRoute,
7+
createRoute,
8+
createRouter,
9+
} from '../../src'
10+
11+
describe('errorComponent (server)', () => {
12+
it('renders the route error component when a loader throws during SSR', async () => {
13+
const rootRoute = createRootRoute()
14+
15+
const indexRoute = createRoute({
16+
getParentRoute: () => rootRoute,
17+
path: '/',
18+
loader: () => {
19+
throw new Error('loader boom')
20+
},
21+
component: () => <div>Index route</div>,
22+
errorComponent: ({ error }) => (
23+
<div data-testid="error-component">Route error: {error.message}</div>
24+
),
25+
})
26+
27+
const routeTree = rootRoute.addChildren([indexRoute])
28+
const router = createRouter({
29+
routeTree,
30+
history: createMemoryHistory({
31+
initialEntries: ['/'],
32+
}),
33+
isServer: true,
34+
})
35+
36+
await router.load()
37+
38+
const html = await renderToStringAsync(() => (
39+
<RouterProvider router={router} />
40+
))
41+
42+
expect(router.state.statusCode).toBe(500)
43+
expect(html).toContain('data-testid="error-component"')
44+
expect(html).toContain('loader boom')
45+
expect(html).not.toContain('Index route')
46+
})
47+
})

0 commit comments

Comments
 (0)