-
Notifications
You must be signed in to change notification settings - Fork 727
docs: Update Cypress Testing Library scoping example #373
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,9 +27,8 @@ and `queryAllBy` commands off the global `cy` object. | |
[See the `DOM Testing Library` docs for reference](https://testing-library.com/docs/dom-testing-library/api-queries). | ||
|
||
> Note: the `get*` queries are not supported because for reasonable Cypress tests you | ||
> need retryability and `find*` queries already support that. The reason the `query*` | ||
> variants are supported is to allow you to assert that elements do _not_ appear on | ||
> the screen. | ||
> need retryability and `find*` queries already support that. `query*` queries are not | ||
> necessary, but supported. | ||
|
||
## With TypeScript | ||
|
||
|
@@ -53,9 +52,12 @@ To show some simple examples (from | |
|
||
```javascript | ||
cy.findAllByText('Jackie Chan').click() | ||
cy.queryByText('Button Text').should('exist') | ||
cy.queryByText('Non-existing Button Text').should('not.exist') | ||
cy.queryByLabelText('Label text', {timeout: 7000}).should('exist') | ||
cy.findByText('Button Text').should('exist') | ||
cy.findByText('Non-existing Button Text').should('not.exist') | ||
cy.findByLabelText('Label text', {timeout: 7000}).should('exist') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. I'm glad that we're keeping all of the |
||
|
||
// findAllByText _inside_ a form element | ||
cy.get('form').findByText('Button Text').should('exist') | ||
cy.get('form').within(() => { | ||
NicholasBoll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cy.findByText('Button Text').should('exist') | ||
}) | ||
|
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.
query*
queries are no longer needed for asserting that elements do not appear in the DOM. Afind*
query can do that instead: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.
I'd include a note about why they are "not necessary", including version when the find* change was added, and mention plans for future deprecation here.
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.
Agreed with @alexkrolick here 👍
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.
I think
find
was changed in testing-library/cypress-testing-library#78 and released as5.0.0
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.
How does the following sound?
https://github.com/testing-library/testing-library-docs/pull/373/files#diff-6245e2573aa625d927375e2065f25b1cR29-R32