Skip to content

toBeDisabled matcher proposal #18

@callada

Description

@callada

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions