Skip to content
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

When typing in a disabled input onChange is still called #152

Closed
roy-bakker-new10 opened this issue Jul 24, 2019 · 3 comments · Fixed by #160
Closed

When typing in a disabled input onChange is still called #152

roy-bakker-new10 opened this issue Jul 24, 2019 · 3 comments · Fixed by #160
Labels

Comments

@roy-bakker-new10
Copy link

roy-bakker-new10 commented Jul 24, 2019

Test:

import React from 'react'
import { render } from '@testing-library/react'
import userEvent from '@testing-library/user-event'

    it('should not call onChange function when typing in a disabled field', () => {
        const onChange = jest.fn()
        const { getByPlaceholderText } = render(
            <input
                disabled
                id="test-id"
                name="test-name"
                onChange={onChange}
                placeholder="placeholder"
            />
        )
        userEvent.type(getByPlaceholderText('placeholder'), 'foo')
        expect(onChange).not.toHaveBeenCalled()
    })

I expect this test to succeed but it isn't.

Output:

    Expected mock function not to be called but it was called with:
      [{"_dispatchInstances": null, "_dispatchListeners": null, "_targetInst": null, "bubbles": null, "cancelable": null, "currentTarget": [Function currentTarget], "defaultPrevented": null, "dispatchConfig": null, "eventPhase": null, "isDefaultPrevented": [Function functionThatReturnsFalse], "isPropagationStopped": [Function functionThatReturnsFalse], "isTrusted": null, "nativeEvent": null, "target": null, "timeStamp": [Function timeStamp], "type": null}], [{"_dispatchInstances": null, "_dispatchListeners": null, "_targetInst": null, "bubbles": null, "cancelable": null, "currentTarget": [Function currentTarget], "defaultPrevented": null, "dispatchConfig": null, "eventPhase": null, "isDefaultPrevented": [Function functionThatReturnsFalse], "isPropagationStopped": [Function functionThatReturnsFalse], "isTrusted": null, "nativeEvent": null, "target": null, "timeStamp": [Function timeStamp], "type": null}], [{"_dispatchInstances": null, "_dispatchListeners": null, "_targetInst": null, "bubbles": null, "cancelable": null, "currentTarget": [Function currentTarget], "defaultPrevented": null, "dispatchConfig": null, "eventPhase": null, "isDefaultPrevented": [Function functionThatReturnsFalse], "isPropagationStopped": [Function functionThatReturnsFalse], "isTrusted": null, "nativeEvent": null, "target": null, "timeStamp": [Function timeStamp], "type": null}]
@weyert
Copy link

weyert commented Jul 28, 2019

Yes, at the moment we don't really check whether the input field is disabled or not.

Maybe this change is enough?
https://github.com/weyert/user-event/tree/ignore-disabled-elements

@Elecweb
Copy link

Elecweb commented Aug 1, 2019

It's also happened in readOnly as well.

is it intended for not testing too much implementation?

Gpx added a commit that referenced this issue Aug 27, 2019
Closes #152

BREAKING CHANGE: disabled or readonly inputs won't be typeable anymore
Gpx added a commit that referenced this issue Aug 27, 2019
Closes #152

BREAKING CHANGE: disabled or readonly inputs won't be typeable anymore
@Gpx Gpx closed this as completed in #160 Aug 27, 2019
@Gpx
Copy link
Member

Gpx commented Aug 27, 2019

🎉 This issue has been resolved in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Gpx Gpx added the released label Aug 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants