File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
docs/react-testing-library Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,20 @@ test('change values via the fireEvent.change method', () => {
28
28
expect (input .value ).toBe (' a' )
29
29
})
30
30
31
+ test (' select drop-downs must use the fireEvent.change' , () => {
32
+ const handleChange = jest .fn ()
33
+ const { container } = render (< select onChange= {handleChange}>< option value= " 1" > 1 < / option>< option value= " 2" > 2 < / option>< / select> )
34
+ const select = container .firstChild ;
35
+ const option1 = container .getElementsByTagName (" option" ).item (0 );
36
+ const option2 = container .getElementsByTagName (" option" ).item (1 );
37
+
38
+ fireEvent .change (select, {target: {value: " 2" }});
39
+
40
+ expect (handleChange).toHaveBeenCalledTimes (1 );
41
+ expect (option1 .selected ).toBe (false );
42
+ expect (option2 .selected ).toBe (true );
43
+ })
44
+
31
45
test (' checkboxes (and radios) must use fireEvent.click' , () => {
32
46
const handleChange = jest .fn ()
33
47
const { container } = render (
You can’t perform that action at this time.
0 commit comments