Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/react-testing-library/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ test('change values via the fireEvent.change method', () => {
expect(input.value).toBe('a')
})

test('select drop-downs must use the fireEvent.change', () => {
const handleChange = jest.fn()
const { container } = render(<select onChange={handleChange}><option value="1">1</option><option value="2">2</option></select>)
const select = container.firstChild;
const option1 = container.getElementsByTagName("option").item(0);
const option2 = container.getElementsByTagName("option").item(1);

fireEvent.change(select, {target: {value: "2"}});

expect(handleChange).toHaveBeenCalledTimes(1);
expect(option1.selected).toBe(false);
expect(option2.selected).toBe(true);
})

test('checkboxes (and radios) must use fireEvent.click', () => {
const handleChange = jest.fn()
const { container } = render(
Expand Down