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
chore: add option to get specific query suggestions #627
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ae31e42:
|
Codecov Report
@@ Coverage Diff @@
## master #627 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 24 24
Lines 559 565 +6
Branches 140 142 +2
=========================================
+ Hits 559 565 +6
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks!
🎉 This PR is included in version 7.14.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Great idea, thank you! I'm interested if there's any followup work we can do to provide more suggestions to users, especially in the linter plugins. |
I'm not entirely the right person to answer that question. But as far as I understand linters and understood from a Twitter thread, that will be a hard thing to do. Which is why The thing is, linters verify on a line-by-line basis. They don't eval the code. And So, that's entirely why we have testing-playground (soon to be official! ❤️) But maybe @benmonro has an idea on how to get more out of the suggestions? |
Maybe we can add a new method that will return a list of suggestions ordered by relevance ? |
Do you have a specific use case in mind? I'm not sure if a function like this belongs to The base functionality that you describe is also quite trivial for other libraries to build themselves, by just using |
I wrote that but I agree with you, testing library shouldn't do this |
@nickmccurdy what did you have in mind? As Stephan mentioned the lint plugin can only analyze code statically. In order to make a suggestion you need to inspect a live dom. I am still curious though because I do love writing lint rules. 🙂 |
@kentcdodds @smeijer if we're adding test id to this shouldn't it check config to rather than hard coding to data-testid attribute? Not that big of a deal but our team uses an alternate attribute |
@benmonro, you're right. We should use the config for that. |
1 - Add support for getting specific query method suggestions
What:
I've added an option to specify the desired method to the
getSuggestedQuery
method.Why:
To enable tools (such as https://testing-playground.com) to show specific suggestions instead of only the most recommended one.
How:
getSuggestedQuery
accepted the argumentselement, variant
, I've extended that toelement, variant, method
.Method defaults to "best", but if specified, only the requested query will be suggested, or none at all.
This enables us to use it like:
If that call results in a valid suggestion, the suggestion is returned otherwise it will return
undefined
. It will not fall back to alternative methods!The default behavior of the method has been left unchanged. A call like:
Still returns either the best query available, or
undefined
.2 - added
getByTestId
suggestionSorry, I should learn to limit the scope of pull-requests. Even when they are tiny.
While working on the above, I noticed that a suggestion for
getByTestId
wasn't implemented. Testing-playground will render it red! But when there are really no other options, this query should still be suggested. It is part of the library after all.So, I've also added the
getByTestId
suggestion, as last option available.Checklist:
docs site