-
Notifications
You must be signed in to change notification settings - Fork 40
prefer-to-have-value having unintended effects #117
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
Comments
@juzerzarif thank you for reporting this. that was quick, just published that rule last night. :). we have some options we can look at. one is to use suggest instead of a fixer for objects like that. would love to welcome a PR if you want to take a stab at it. |
@benmonro That sounds like a good idea, what do you think of providing an option to pick between the rule providing a suggestion, fix, or just being off for |
@juzerzarif that might work, another thought would be to check the assignment/value of the argument to make sure it's coming from a dom node. we did this in prefer-in-document: https://github.com/testing-library/eslint-plugin-jest-dom/blob/master/src/rules/prefer-in-document.js#L104-L126 perhaps we could just extract that out and use that? |
@benmonro That would be the best of both worlds, sounds like the way to go! I can mess around with it and see about a PR this weekend |
@juzerzarif another use case just occurred to me. this is totally optional, but would be wonderful if you want to implement it. basically,
|
Did you mean to mention me on this? or was it just a misclick? |
doh, yes it was a mis-click sorry |
@benmonro Are you saying it should still report an error if it is a different query than a |
Yeah that's what I'm thinking |
But since we're only reporting an error when the object being queried came from a testing library query, wouldn't the fix that the user would have to implement be pretty much the same as the fix that the autofix would provide? Like if you had queries similar to the ones in the docs https://github.com/testing-library/jest-dom#tohavevalue, wouldn't we want to autofix those too? |
well, the problem is that the answer to your question is "maybe." it kinda depends on the element. You could do a suggest for those, but I think the fixer should only change code we can be certain won't have bad consequences. hopefully i'm making sense. :) |
Ah, yeah that makes sense to me. I think a suggestion for the other cases is a good alternative |
🎉 This issue has been resolved in version 3.6.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
eslint-plugin-jest-dom
version: 3.5.0node
version: 10.22.0npm
version: 6.14.6Relevant code or config
What you did: ^
What happened:
Prefer .toHaveValue() over other attribute checks
Problem description:
The new rule
prefer-to-have-value
is causing unintended warnings when checking thevalue
key on objects that are not DOM elements.Suggested solution:
I'm not sure if there's a graceful solution that can allow for triggering warnings on
element.value
but not onobj.value
(let me know if I'm wrong!). But I think a reasonable middle ground would be to allow a configuration option to only trigger a warning onexpect(element).toHaveAttribute('value', 'someValue')
so I don't have to individually turn off the rule everywhere I'm testing generators.The text was updated successfully, but these errors were encountered: