eslint-plugin-jest-dom icon indicating copy to clipboard operation
eslint-plugin-jest-dom copied to clipboard

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

Open ricardozv28 opened this issue 4 years ago • 5 comments

  • 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:

ricardozv28 avatar Sep 24 '21 21:09 ricardozv28

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

https://github.com/testing-library/eslint-plugin-jest-dom/blob/ee6af993112ac73a4053294e2e55e7ff2ba926f9/src/rules/prefer-to-have-value.js#L35-L35

@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)

G-Rath avatar Dec 26 '21 22:12 G-Rath

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

MichaelDeBoey avatar Dec 26 '21 22:12 MichaelDeBoey

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.

juzerzarif avatar Dec 26 '21 22:12 juzerzarif

@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)

G-Rath avatar Dec 26 '21 22:12 G-Rath

Yeah adding a note to the docs makes sense to me

benmonro avatar Dec 27 '21 07:12 benmonro

:tada: This issue has been resolved in version 5.0.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Jun 04 '23 20:06 github-actions[bot]