-
Notifications
You must be signed in to change notification settings - Fork 153
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
Unhelpful error messages for query* commands #103
Comments
I also noticed |
I also noticed the command does not retry queries even though there is a comment that says it doesn't retry for |
These are fantastic recommendations! Would you be willing to make contributions to improve things as you suggest? |
Yes! Working on those now |
@kentcdodds Question: I read up on all the query types and looked through implementations in this repository:
Does it make still make sense to not retry I'm debating removing the restriction to not retry |
|
@alexkrolick thanks! I agree. In order to have more useful errors, I changed the logic a bit to follow the same codepath as find queries, but with a 1ms duration. This keeps the messages consistent. As I was thinking about my original issue with the more complex We can see if that seems like the way to go |
* Add element selector infomation for debugging (outlines element when you click on command) (fixes testing-library#103) * Add @testing-library/dom errors (from `get*` queries) to failure messages - these are more helpful than the generic `find*('input') does not exist` messages (fixes testing-library#103) * Add retryability to `findBy*` when multiple elements are found (fixes testing-library#83) * Add option to disable logging of all commands * `query*` and `find*` have a consistent code path and error messaging (fixes testing-library#103) * Remove usage of Cypress commands in queries (fixes testing-library#103)
* Add element selector information for debugging (outlines element when you click on command) (fixes testing-library#103) * Add @testing-library/dom errors (from `get*` queries) to failure messages - these are more helpful than the generic `find*('input') does not exist` messages (fixes testing-library#103) * Add retryability to `findBy*` when multiple elements are found (fixes testing-library#83) * Add option to disable logging of all commands * `query*` and `find*` have a consistent code path and error messaging (fixes testing-library#103) * Remove usage of Cypress commands in queries (fixes testing-library#103)
* feat: add more helpful debugging information to queries * Add element selector information for debugging (outlines element when you click on command) (fixes #103) * Add @testing-library/dom errors (from `get*` queries) to failure messages - these are more helpful than the generic `find*('input') does not exist` messages (fixes #103) * Add retryability to `findBy*` when multiple elements are found (fixes #83) * Add option to disable logging of all commands * `query*` and `find*` have a consistent code path and error messaging (fixes #103) * Remove usage of Cypress commands in queries (fixes #103) * feat: add ability for queries to inherit previous subject * Fixes #109 without breaking change caused by #100 * feat: add parent/child log type detection * chore: implement feedback * docs: update readme to complete my thought process * slightly simplify config fn * Update README.md Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com> Closes #103, Closes #109, Closes #110
🎉 This issue has been resolved in version 5.2.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
cypress-testing-library
version: 5.1.0Relevant code or config
Test
HTML
What happened:
The first passes fine. The
consoleProps
do not have the same description level as built-in Cypress commandsThe second fails, but not as expected. The issue is the label element could not be found by the text "Test 2"
The third fails, but not as expected. The issue is the label element doesn't have a
for
attribute and has no way to associate with an inputThe fourth fails, but not as expected. The issue is the label element has no corresponding input element.
All failures result in this error message:
Note that the failure is on the
cy.click
command and not thequeryByLabelText
command. This is because https://github.com/testing-library/cypress-testing-library/blob/master/src/index.js#L87 simply wraps any returned value in an jQuery wrapper. It seems to be returning an empty object rather than an empty NodeList which Cypress automatically detects.Also notice the error mentions the previous command was
cy.then
, even though that command wasn't actually used anywhere in user code. This is confusing. This is because of https://github.com/testing-library/cypress-testing-library/blob/master/src/index.js#L84 (use ofcy.window().then()
There is also a comment about Promises not working with Cypress retryability which is not accurate. The problem probably comes from the use of
cy.then
. The original intent of Cypress Custom commands was not to use anycy
commands at all. Internal Cypress Commands do not use them. Here's the source code for all the traversal-style commands: https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/traversals.coffee. Notice promises are used in there just fine.Problem description:
Failures to find elements returned from
@testing-library/dom
are unhelpful and confusingSuggested solution:
Refactor the use of Cypress Custom Commands a bit to better handle not finding an element and remove the use of
cy.window()
andcy.then
. Cypress has acy.state
function and it saves thewindow
incy.state('window')
which is synchronously resolved.Also try some of the query commands with known failures and see if the errors are useful. This goes a long way to guiding developers to finding out why something went wrong.
The text was updated successfully, but these errors were encountered: