@@ -10,9 +10,9 @@ const renderToggleSwitch = (props?: Partial<ToggleSwitchProps>) =>
10
10
) ;
11
11
12
12
describe ( '<ToggleSwitch />' , ( ) => {
13
- it ( 'should render a checkbox ' , ( ) => {
13
+ it ( 'should render a switch ' , ( ) => {
14
14
renderToggleSwitch ( ) ;
15
- expect ( screen . getByRole ( 'checkbox ' ) ) . toBeInTheDocument ( ) ;
15
+ expect ( screen . getByRole ( 'switch ' ) ) . toBeInTheDocument ( ) ;
16
16
} ) ;
17
17
18
18
it ( 'should render a default value if passed' , ( ) => {
@@ -21,32 +21,34 @@ describe('<ToggleSwitch />', () => {
21
21
Hello world
22
22
</ ToggleSwitch > ,
23
23
) ;
24
- const checkbox = screen . getByRole ( 'checkbox ' ) ;
25
- expect ( checkbox ) . not . toBeChecked ( ) ;
24
+ const switchElement = screen . getByRole ( 'switch ' ) ;
25
+ expect ( switchElement ) . not . toBeChecked ( ) ;
26
26
rerender (
27
27
< ToggleSwitch onChange = { ( ) => { } } checked = { true } >
28
28
Hello world
29
29
</ ToggleSwitch > ,
30
30
) ;
31
- expect ( checkbox ) . toBeChecked ( ) ;
31
+ expect ( switchElement ) . toBeChecked ( ) ;
32
32
} ) ;
33
33
34
34
it ( 'should apply the same id to <label> and <input>' , ( ) => {
35
35
const { container } = renderToggleSwitch ( {
36
36
name : 'Some text goes here' ,
37
37
} ) ;
38
38
const label = container . querySelector ( 'label' ) ;
39
- const checkbox = screen . getByRole ( 'checkbox ' ) ;
39
+ const switchElement = screen . getByRole ( 'switch ' ) ;
40
40
41
- expect ( label ?. getAttribute ( 'for' ) ) . toBe ( checkbox ?. getAttribute ( 'id' ) ) ;
41
+ expect ( label ?. getAttribute ( 'for' ) ) . toBe (
42
+ switchElement ?. getAttribute ( 'id' ) ,
43
+ ) ;
42
44
} ) ;
43
45
44
46
it ( 'should apply a unique id for each instance' , ( ) => {
45
47
renderToggleSwitch ( { name : 'Some text goes here' } ) ;
46
48
renderToggleSwitch ( { name : 'Some other text goes here' } ) ;
47
49
48
50
const [ id1 , id2 ] = screen
49
- . getAllByRole ( 'checkbox ' )
51
+ . getAllByRole ( 'switch ' )
50
52
. map ( it => it . getAttribute ( 'id' ) ) ;
51
53
52
54
expect ( id1 ) . not . toBe ( id2 ) ;
@@ -58,15 +60,15 @@ describe('<ToggleSwitch />', () => {
58
60
Hello world
59
61
</ ToggleSwitch > ,
60
62
) ;
61
- const checkbox = screen . getByRole ( 'checkbox ' ) ;
62
- const idFirstRender = checkbox . getAttribute ( 'id' ) ;
63
+ const switchElement = screen . getByRole ( 'switch ' ) ;
64
+ const idFirstRender = switchElement . getAttribute ( 'id' ) ;
63
65
64
66
rerender (
65
67
< ToggleSwitch onChange = { ( ) => { } } checked = { undefined } >
66
68
Hello world
67
69
</ ToggleSwitch > ,
68
70
) ;
69
- const idSecondRender = checkbox . getAttribute ( 'id' ) ;
71
+ const idSecondRender = switchElement . getAttribute ( 'id' ) ;
70
72
71
73
expect ( idFirstRender ) . toBe ( idSecondRender ) ;
72
74
} ) ;
@@ -79,10 +81,10 @@ describe('<ToggleSwitch />', () => {
79
81
} ) ;
80
82
81
83
const label = container . querySelector ( 'label' ) ;
82
- const checkbox = screen . getByRole ( 'checkbox ' ) ;
84
+ const switchElement = screen . getByRole ( 'switch ' ) ;
83
85
84
86
expect ( label ?. getAttribute ( 'for' ) ) . toBe ( id ) ;
85
- expect ( checkbox . getAttribute ( 'id' ) ) . toBe ( id ) ;
87
+ expect ( switchElement . getAttribute ( 'id' ) ) . toBe ( id ) ;
86
88
} ) ;
87
89
88
90
it ( 'should set arbitrary props (rest) on input' , ( ) => {
@@ -91,9 +93,9 @@ describe('<ToggleSwitch />', () => {
91
93
tabIndex : - 1 ,
92
94
} ) ;
93
95
94
- const checkbox = screen . getByRole ( 'checkbox ' ) ;
95
- expect ( checkbox . getAttribute ( 'name' ) ) . toBe ( 'toggle' ) ;
96
- expect ( checkbox . getAttribute ( 'tabIndex' ) ) . toBe ( '-1' ) ;
96
+ const switchElement = screen . getByRole ( 'switch ' ) ;
97
+ expect ( switchElement . getAttribute ( 'name' ) ) . toBe ( 'toggle' ) ;
98
+ expect ( switchElement . getAttribute ( 'tabIndex' ) ) . toBe ( '-1' ) ;
97
99
} ) ;
98
100
99
101
it ( 'should render additional props if passed' , ( ) => {
0 commit comments