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', () => {
2828 expect (input .value ).toBe (' a' )
2929})
3030
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+
3145test (' checkboxes (and radios) must use fireEvent.click' , () => {
3246 const handleChange = jest .fn ()
3347 const { container } = render (
You can’t perform that action at this time.
0 commit comments