Skip to content

Commit 1cef96f

Browse files
authored
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.
1 parent 246c0cf commit 1cef96f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

docs/cypress-testing-library/intro.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ 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 not
31+
> necessary, but supported.
3332
3433
## With TypeScript
3534

@@ -53,9 +52,12 @@ To show some simple examples (from
5352

5453
```javascript
5554
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')
55+
cy.findByText('Button Text').should('exist')
56+
cy.findByText('Non-existing Button Text').should('not.exist')
57+
cy.findByLabelText('Label text', {timeout: 7000}).should('exist')
58+
59+
// findAllByText _inside_ a form element
60+
cy.get('form').findByText('Button Text').should('exist')
5961
cy.get('form').within(() => {
6062
cy.findByText('Button Text').should('exist')
6163
})

0 commit comments

Comments
 (0)