-
Notifications
You must be signed in to change notification settings - Fork 412
Closed
Description
Describe the feature you'd like:
I would like to have a matcher that would check if the form element is disabled from user's perspective.
In this case, simply checking the 'disabled' attribute is not enough.
Describe alternatives you've considered:
In many cases .toHaveAttribute('disabled')
is sufficient alternative.
But I think that the dedicated matcher would be less dependent on the implementation details
Teachability, Documentation, Adoption, Migration Strategy:
Examples and comparison with toHaveAttribute
matcher.
// in simple cases toHaveAttribute and toBeDisabled behave the same
// ...
// <button disabled={true}>CLICK</button>
expect(getByText(container, 'CLICK')).toHaveAttribute('disabled')
expect(getByText(container, 'CLICK')).toBeDisabled()
// ...
// toBeDisabled can detect when a disabled state is inherited
// ...
// <fieldset disabled={true}><button>CLICK</button></fieldset>
expect(getByText(container, 'CLICK')).not.toHaveAttribute('disabled')
expect(getByText(container, 'CLICK')).toBeDisabled()
// ...
// 'a' element is not disabled, even if it has the 'disabled' attribute
// ...
// <a href="http://..." disabled={true}>CLICK</a>
expect(getByText(container, 'CLICK')).toHaveAttribute('disabled')
expect(getByText(container, 'CLICK')).not.toBeDisabled()
// ...
Metadata
Metadata
Assignees
Labels
No labels