Skip to content

onChange is called when checkbox is disabled #275

Closed
@rug1

Description

@rug1

Hi 👋 Thanks for the great library! Think I may have found a bug but if not I would love to know what I'm doing wrong here.

  • react-testing-library version: 5.4.4
  • react version: 16.7.0
  • node version: 10.15.0
  • npm (or yarn) version: yarn 1.10.1

Relevant code or config:

test('disabled checkbox cannot be selected', () => {
  const onChange = jest.fn()
  const {getByTestId} = render(
    <input
      type="checkbox"
      onChange={onChange}
      data-testid="checkbox"
      disabled
    />,
  )
  const checkbox = getByTestId('checkbox')
  fireEvent.click(checkbox)
  expect(onChange).not.toHaveBeenCalled() // this fails
})

What you did:

I wrote a test to check that a checkbox onChange function would not be called if the checkbox is disabled.

What happened:

The test failed saying that the onChange function had been called.

Reproduction:

https://codesandbox.io/s/91684p354

Problem description:

The test should pass. onChange functions should not be called in the test if the checkbox is disabled.

Suggested solution:

Not sure, haven't looked into the code yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is neededjsdomIssue with JSDOM environmentneeds investigation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions