Skip to content

Commit 3448319

Browse files
authored
docs: Update Cypress Testing Library scoping example (#373)
* docs: Update Cypress Testing Library scoping example Recently testing-library/cypress-testing-library#108 added a way to take the previous subject of a previous command to scope the query. Also `find*` queries handle `.should('not.exist')` and should be preferred over `query*` which require additional logic for eventual non-existence queries. * docs: update note about other query types
1 parent cf1eebe commit 3448319

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/cypress-testing-library/intro.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ and `queryAllBy` commands off the global `cy` object.
2727
[See the `DOM Testing Library` docs for reference](https://testing-library.com/docs/dom-testing-library/api-queries).
2828

2929
> Note: the `get*` queries are not supported because for reasonable Cypress tests you
30-
> need retryability and `find*` queries already support that. The reason the `query*`
31-
> variants are supported is to allow you to assert that elements do _not_ appear on
32-
> the screen.
30+
> need retryability and `find*` queries already support that. `query*` queries are no longer
31+
> necessary since v5 and will be removed in v6. `find*` fully support built-in Cypress
32+
> assertions (removes the only use-case for `query*`).
3333
3434
## With TypeScript
3535

@@ -53,12 +53,12 @@ To show some simple examples (from
5353

5454
```javascript
5555
cy.findAllByText('Jackie Chan').click()
56-
cy.queryByText('Button Text').should('exist')
57-
cy.queryByText('Non-existing Button Text').should('not.exist')
58-
cy.queryByLabelText('Label text', {timeout: 7000}).should('exist')
59-
cy.get('form').within(() => {
60-
cy.findByText('Button Text').should('exist')
61-
})
56+
cy.findByText('Button Text').should('exist')
57+
cy.findByText('Non-existing Button Text').should('not.exist')
58+
cy.findByLabelText('Label text', {timeout: 7000}).should('exist')
59+
60+
// findAllByText _inside_ a form element
61+
cy.get('form').findByText('Button Text').should('exist')
6262
cy.get('form').then(subject => {
6363
cy.findByText('Button Text', {container: subject}).should('exist')
6464
})

0 commit comments

Comments
 (0)