/
App.test.tsx
47 lines (40 loc) · 1.15 KB
/
App.test.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
import { render, screen } from '@testing-library/react'
import { composeStories } from '@storybook/testing-react'
import { posts } from './mockData'
import * as stories from './App.stories'
const { Loading, Data, Error } = composeStories(stories)
it('renders in the loading state', () => {
render(<Loading />)
expect(
screen.getByRole('heading', {
name: /storybook testing example/i,
level: 1,
}),
).toBeInTheDocument()
expect(screen.getByLabelText(/loading/i)).toBeInTheDocument()
})
it('renders with data', async () => {
render(<Data />)
expect(
screen.getByRole('heading', {
name: /storybook testing example/i,
level: 1,
}),
).toBeInTheDocument()
for (const post of posts) {
expect(
await screen.findByRole('heading', { name: post.title, level: 2 }),
).toBeDefined()
expect(screen.getByText(post.body)).toBeDefined()
}
})
it('handles errors', async () => {
render(<Error />)
expect(
screen.getByRole('heading', {
name: /storybook testing example/i,
level: 1,
}),
).toBeInTheDocument()
expect(await screen.findByText(/error loading posts/i)).toBeInTheDocument()
})