Skip to content

Latest version not reporting/suggesting changes on disabled/value attributes #203

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

Closed
ricardozv28 opened this issue Sep 24, 2021 · 6 comments · Fixed by #255
Closed

Latest version not reporting/suggesting changes on disabled/value attributes #203

ricardozv28 opened this issue Sep 24, 2021 · 6 comments · Fixed by #255
Labels

Comments

@ricardozv28
Copy link
Contributor

  • eslint-plugin-jest-dom version: 3.9.2
  • node version: 14.17.6
  • npm version: 6.14.15

Relevant code or config

    const button = getByRole('button', { name: 'My Button' });
    expect(button.disabled).toBe(true);

    const input = getByLabelText('My Input');
    expect(input.value).toBe('value');

What you did:
run eslint using npm run eslint

What happened:
eslint is not reporting suggested changes when using .disabled or .value

Reproduction repository:
https://github.com/ricardozv28/eslint-plugin-jest-dom-bug

Problem description:
When using the latest versions of the package, eslint won't report on .disabled or .value (I haven't tested the other rules but those are the ones that I caught when adding the plugin to an existing repo at work)

Here is a screenshot of the output of the reproducible projet, it is just showing the ones from eslint-plugin-testing-librarry
image

downgrading to version 3.6.3 make the errors appear
image

version 3.6.4 only reports the toHaveValue
image

Suggested solution:

@G-Rath
Copy link
Collaborator

G-Rath commented Dec 26, 2021

It looks like at least for prefer-to-have-value we currently only support *ByRole:

!!query.match(/^(get|find|query)(All)?ByRole$/) &&

@benmonro @MichaelDeBoey do either of you know if there's a reason for that? My understanding is that all the queries return elements, so we should be ok to apply this rule to any of the query methods.

(I'm guessing this is probably also the case for prefer-enabled-disabled but have not found where it's actually doing the check yet)

@MichaelDeBoey
Copy link
Member

@G-Rath It seems like this was first introduced by @juzerzarif in #122

@juzerzarif
Copy link
Contributor

I believe it was because ByRole queries are the only ones where we can be definitely sure that the element returned is an input element that has a value attribute (via the role specified). It was a while ago though so @benmonro can correct me if I'm wrong.

@G-Rath
Copy link
Collaborator

G-Rath commented Dec 26, 2021

@juzerzarif that makes sense - in that case if we want to keep it like that we should probably stick a note in the doc; could also be worth considering if we want to provide a loose option for people who'd prefer to risk the false positives.

(I imagine that's the case with a number of rules - could be interesting to see if optionally using type-checking if available could let the rules be smarter)

@benmonro
Copy link
Member

Yeah adding a note to the docs makes sense to me

@github-actions
Copy link

github-actions bot commented Jun 4, 2023

🎉 This issue has been resolved in version 5.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants