1
1
import CRadio from '..'
2
- import { render , userEvent } from '@/tests/test-utils'
2
+ import { render , userEvent , screen } from '@/tests/test-utils'
3
3
4
4
const renderComponent = ( props ) => {
5
5
const inlineAttrs = ( props && props . inlineAttrs ) || ''
@@ -18,52 +18,50 @@ it('should render correctly', () => {
18
18
19
19
it ( 'should display a disabled radio' , ( ) => {
20
20
const inlineAttrs = 'isDisabled'
21
- const { getByText , container } = renderComponent ( { inlineAttrs } )
22
- const input = container . querySelector ( 'input ')
21
+ renderComponent ( { inlineAttrs } )
22
+ const input = screen . getByLabelText ( 'radio ')
23
23
24
24
expect ( input ) . toHaveAttribute ( 'disabled' )
25
- expect ( getByText ( 'radio' ) . parentNode ) . toHaveStyle ( 'cursor: not-allowed;' )
25
+ expect ( input . parentNode ) . toHaveStyle ( 'cursor: not-allowed;' )
26
26
} )
27
27
28
28
it ( 'should display a radio with a checked state' , ( ) => {
29
29
const inlineAttrs = 'isChecked'
30
- const { container } = renderComponent ( { inlineAttrs } )
31
- const input = container . querySelector ( 'input ')
30
+ renderComponent ( { inlineAttrs } )
31
+ const input = screen . getByLabelText ( 'radio ')
32
32
33
33
expect ( input ) . toBeChecked ( )
34
34
} )
35
35
36
36
it ( 'should display a radio with an unchecked state' , ( ) => {
37
37
const inlineAttrs = ':isChecked="false"'
38
- const { container } = renderComponent ( { inlineAttrs } )
39
- const input = container . querySelector ( 'input ')
38
+ renderComponent ( { inlineAttrs } )
39
+ const input = screen . getByLabelText ( 'radio ')
40
40
41
41
expect ( input ) . not . toBeChecked ( )
42
42
} )
43
43
44
44
test ( 'Uncontrolled - should not check if disabled' , async ( ) => {
45
45
const inlineAttrs = 'isDisabled'
46
- const { container, getByText } = renderComponent ( { inlineAttrs } )
47
- const input = container . querySelector ( 'input' )
48
- const radio = getByText ( 'radio' )
46
+ renderComponent ( { inlineAttrs } )
47
+ const input = screen . getByLabelText ( 'radio' )
49
48
50
49
expect ( input ) . toBeDisabled ( )
51
50
52
- await userEvent . click ( radio )
51
+ await userEvent . click ( input )
53
52
54
53
expect ( input ) . not . toBeChecked ( )
55
54
} )
56
55
57
56
test ( 'Uncontrolled - should be checked always' , async ( ) => {
58
- const { container, getByText } = renderComponent ( )
59
- const input = container . querySelector ( 'input' )
60
- const radio = getByText ( 'radio' )
57
+ renderComponent ( )
58
+ const input = screen . getByLabelText ( 'radio' )
61
59
62
60
// click the first time, it's checked
63
- await userEvent . click ( radio )
61
+ await userEvent . click ( input )
64
62
expect ( input ) . toBeChecked ( )
65
63
66
64
// click the second time, it should be still checked
67
- await userEvent . click ( radio )
65
+ await userEvent . click ( input )
68
66
expect ( input ) . toBeChecked ( )
69
67
} )
0 commit comments