-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
input.test.tsx
59 lines (56 loc) · 1.47 KB
/
input.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
48
49
50
51
52
53
54
55
56
57
58
59
import '@testing-library/jest-dom'
import { render, screen, userEvent } from '../utils/test-utils'
import { Input } from './Input'
describe('Input', () => {
it('should render the input', () => {
render(
<Input
name="email"
type="email"
error={undefined}
placeholder="Email"
label="Email Address"
aria-label="Email Address"
/>,
)
expect(screen.getByText('Email Address')).toBeInTheDocument()
expect(screen.getByRole('textbox', {
name: /email address/i,
})).toBeInTheDocument()
})
it('should change input value', () => {
render(
<Input
name="email"
type="email"
error={undefined}
placeholder="Email"
label="Email Address"
aria-label="Email Address"
/>,
)
screen.logTestingPlaygroundURL()
const input = screen.getByRole('textbox', {
name: /email address/i,
})
expect(input).toBeInTheDocument()
userEvent.type(input, '1337')
expect(input).toHaveValue('1337')
})
it('should render the input with error', () => {
render(
<Input
name="email"
type="email"
placeholder="Email"
label="Email Address"
aria-label="Email Address"
error="Please enter your email"
/>,
)
expect(screen.getByRole('textbox', {
name: /email address/i,
})).toBeInTheDocument()
expect(screen.getByRole('alert')).toHaveTextContent('Please enter your email')
})
})