-
Notifications
You must be signed in to change notification settings - Fork 40
/
App.stories.tsx
executable file
·59 lines (52 loc) · 1.2 KB
/
App.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
import { http, HttpResponse, delay } from 'msw'
import { App } from './App'
const meta = {
title: 'Demos/Fetch',
component: App,
}
export default meta
export const DefaultBehavior = {}
const films = [
{
title: 'A New Hope',
episode_id: 4,
opening_crawl: `(Mocked) Rebel spaceships have won their first victory against the evil Galactic Empire.`,
},
{
title: 'Empire Strikes Back',
episode_id: 5,
opening_crawl: `(Mocked) Imperial troops are pursuing the Rebel forces across the galaxy.`,
},
{
title: 'Return of the Jedi',
episode_id: 6,
opening_crawl: `(Mocked) Luke Skywalker has returned to his home planet of Tatooine to rescue Han Solo.`,
},
]
export const MockedSuccess = {
parameters: {
msw: {
handlers: [
http.get('https://swapi.dev/api/films/', () => {
return HttpResponse.json({
results: films,
})
}),
],
},
},
}
export const MockedError = {
parameters: {
msw: {
handlers: [
http.get('https://swapi.dev/api/films/', async () => {
await delay(300)
return new HttpResponse(null, {
status: 403,
})
}),
],
},
},
}