-
Notifications
You must be signed in to change notification settings - Fork 1
/
GeneralErrorBoundary.stories.tsx
62 lines (57 loc) · 1.68 KB
/
GeneralErrorBoundary.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { type StoryObj, type Meta } from '@storybook/react'
import { GeneralErrorBoundary } from '~/components/error-boundary.tsx'
import { unstable_createRemixStub as createRemixStub } from '@remix-run/testing'
import { Form } from '@remix-run/react'
import { Button } from '~/components/ui/button.tsx'
export default {
title: 'ErrorBoundary',
component: () => <div>Sample Child Component</div>,
} satisfies Meta<typeof GeneralErrorBoundary>
export const LoaderError = {
decorators: [
Story => {
let RemixStub = createRemixStub([
{
path: '/',
element: <Story />,
ErrorBoundary: GeneralErrorBoundary,
loader: () => {
// throw an error with a status code
throw new Response('Error Message', {
status: 500,
})
},
},
])
return <RemixStub />
},
],
} satisfies StoryObj<typeof GeneralErrorBoundary>
export const ActionError = {
decorators: [
Story => {
// This is how you make remix-specific routes, loaders and actions etc.
// This works for all remix utilities e.g. useLoaderData and even fetchers!
// To see full usage check out the @remix-run/testing tests - the docs are not updated yet for this package.
// https://github.com/remix-run/remix/blob/main/packages/remix-testing/__tests__/stub-test.tsx
let RemixStub = createRemixStub([
{
path: '/',
element: <Story />,
ErrorBoundary: GeneralErrorBoundary,
action: () => {
throw new Response('Unauthorised', {
status: 401,
})
},
},
])
return <RemixStub />
},
],
render: () => (
<Form action="/" method="POST">
<Button type="submit">Submit</Button>
</Form>
),
} satisfies StoryObj<typeof GeneralErrorBoundary>