Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

errorBoundary.test-d.tsx

42 lines1.2 KB

1import { expectTypeOf, test } from 'vitest'
2import { CatchBoundary, createRootRoute, createRouter } from '../src'
3import type { ErrorComponentProps } from '../src'
4​
5test('Solid boundary errors default to Error', () => {
6 expectTypeOf<ErrorComponentProps['error']>().toEqualTypeOf<Error>()
7 expectTypeOf<ErrorComponentProps<unknown>['error']>().toEqualTypeOf<unknown>()
8 ;<CatchBoundary
9 getResetKey={() => 0}
10 onCatch={(error) => {
11 expectTypeOf(error).toEqualTypeOf<Error>()
12 }}
13 errorComponent={({ error }) => {
14 expectTypeOf(error).toEqualTypeOf<Error>()
15 return null
16 }}
17 >
18 <div />
19 </CatchBoundary>
20 const routeTree = createRootRoute({
21 errorComponent: ({ error }) => {
22 expectTypeOf(error).toEqualTypeOf<Error>()
23 return null
24 },
25 onCatch: (error) => {
26 expectTypeOf(error).toEqualTypeOf<Error>()
27 },
28 onError: (error) => {
29 expectTypeOf(error).toBeAny()
30 },
31 })
32 createRouter({
33 routeTree,
34 defaultErrorComponent: ({ error }) => {
35 expectTypeOf(error).toEqualTypeOf<Error>()
36 return null
37 },
38 defaultOnCatch: (error) => {
39 expectTypeOf(error).toEqualTypeOf<Error>()
40 },
41 })
42})