Skip to content

Add example of firing select event #472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2020
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