Skip to content

Commit 94ea50a

Browse files
committed
fix: update retry ability guide and migration guide now that should() and and() will not be queries in v13. see cypress-io/cypress#25738
1 parent f44838e commit 94ea50a

File tree

3 files changed

+31
-51
lines changed

3 files changed

+31
-51
lines changed

docs/guides/core-concepts/retry-ability.mdx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ important to understand the different rules by which they operate.
3737
log.
3838
- **Non-queries** only execute once.
3939

40-
For example, there are 7 queries (2 of them assertions) and 2 non-queries in the
41-
test below.
40+
For example, there are 4 queries, an action, and 2 assertions in
41+
the test below.
4242

4343
```javascript
4444
it('creates an item', () => {
4545
// Non-query commands only execute once.
4646
cy.visit('/')
4747

48-
// The queries .focused() and .should() link together,
48+
// The .focused() query and .should() assertion link together,
4949
// rerunning until the currently focused element has
5050
// the 'new-todo' class
5151
cy.focused().should('have.class', 'new-todo')
@@ -55,7 +55,7 @@ it('creates an item', () => {
5555
// the non-query `.type()`.
5656
cy.get('.header').find('.new-todo').type('todo A{enter}')
5757

58-
// Three queries chained together
58+
// Two queries and an assertion chained together
5959
cy.get('.todoapp').find('.todo-list li').should('have.length', 1)
6060
})
6161
```
@@ -136,12 +136,16 @@ Within a few milliseconds after the DOM updates, the linked queries
136136

137137
## Multiple assertions
138138

139-
Chains of commands are always executed in order, with all previous queries
140-
forming the subject of each following command.
139+
Queries and assertions are always executed in order, and always retry 'from the
140+
top'. If you have multiple assertions, Cypress will retry until each passes
141+
before moving on to the next one.
141142

142-
For example, the following test has the [.get()](/api/commands/get),
143-
[`.should()`](/api/commands/should) and [`.and()`](/api/commands/and) commands
144-
chained together. All three of these are queries.
143+
For example, the following test has [`.should()`](/api/commands/should) and
144+
[`.and()`](/api/commands/and) assertions. `.and()` is an alias of the
145+
`.should()` command, so the second assertion is really a custom callback
146+
assertion in the form of the [`.should(cb)`](/api/commands/should#Function)
147+
function with 2 [`expect`](/guides/references/assertions#BDD-Assertions)
148+
assertions inside of it.
145149

146150
```javascript
147151
it('creates two items', () => {
@@ -151,9 +155,9 @@ it('creates two items', () => {
151155
cy.get('.new-todo').type('todo B{enter}')
152156

153157
cy.get('.todo-list li') // query
154-
.should('have.length', 2) // query
158+
.should('have.length', 2) // assertion
155159
.and(($li) => {
156-
// 2 mocha assertions inside of the .and() query
160+
// 2 mocha assertions inside of the .and() assertion
157161
expect($li.get(0).textContent, 'first item').to.equal('todo a')
158162
expect($li.get(1).textContent, 'second item').to.equal('todo B')
159163
})
@@ -163,7 +167,8 @@ it('creates two items', () => {
163167
Because the first expect statement
164168
(`expect($li.get(0).textContent, 'first item').to.equal('todo a')`) fails, the
165169
second statement is never reached. The `.and()` command fails after timing out,
166-
and the Command Log correctly shows that `.get()` and `.should()` passed, but
170+
and the Command Log correctly shows that the first encountered assertion
171+
`should('have.length', 2)` passed, but
167172
the "first item" assertion failed.
168173

169174
<DocsImage
@@ -179,7 +184,9 @@ will be retried even without any attached assertions until it finds an element
179184
with the given index.
180185

181186
```javascript
182-
cy.get('.todo-list li').should('have.length', 2).eq(3)
187+
cy.get('.todo-list li') // query
188+
.should('have.length', 2) // assertion
189+
.eq(3) // query
183190
```
184191

185192
<DocsImage

docs/guides/references/migration-guide.mdx

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ title: Migration Guide
66

77
This guide details the changes and how to change your code to migrate to Cypress
88
version 13.0.
9-
[See the full changelog for version 12.0](/guides/references/changelog#12-0-0).
9+
[See the full changelog for version 13.0](/guides/references/changelog#13-0-0).
1010

1111
### `cy.readFile()` is now a query command
1212

13-
In Cypress 13, the [`.readFile()`](/api/commands/as) command is now a query.
13+
In Cypress 13, the [`.readFile()`](/api/commands/readFile) command is now a query.
1414
Tests written using it should continue to operate exactly as before; no changes
1515
are necessary.
1616

17-
This means that `readFile()` will re-read the file from disk if any upcoming
18-
command in the same chain fails. Assertions no longer have to be directly
19-
attached.
17+
`readFile()` will re-read the file from disk if any upcoming command in the same
18+
chain fails. Assertions no longer have to be directly attached.
2019

2120
```js
2221
cy.readFile(`users.json`).its('users.123.fullName').should('eq', 'John Doe')
@@ -31,38 +30,12 @@ requested property or the contents didn't match.
3130

3231
#### `.readFile()` can no longer be overwritten with `Cypress.Commands.overwrite()`
3332

34-
However, queries cannot be overwritten using `Cypress.Commands.overwrite()`. If
35-
you were previously overwriting `cy.readFile()`, you will need to put your
36-
custom version under a new name, and update your tests to use it. For example,
37-
you might update this test:
38-
39-
```js
40-
Cypress.Commands.override('readFile', (originalFn, fileName, options) => {
41-
originalFn(fileName, options).then((file) => {
42-
// Do some processing
43-
return updatedFile
44-
})
45-
})
46-
47-
it('reads a file', () => {
48-
cy.readFile('foo.json')
49-
})
50-
```
51-
52-
to something like this:
53-
54-
```js
55-
Cypress.Commands.create('readFileWithExtras', (fileName, options) => {
56-
cy.readFile(fileName, options).then((file) => {
57-
// Do some processing
58-
return updatedFile
59-
})
60-
})
61-
62-
it('reads a file', () => {
63-
cy.readFileWithExtras('foo.json')
64-
})
65-
```
33+
Queries must be overwritten using `Cypress.Commands.overwriteQuery()`. If you
34+
were previously overwriting `cy.readFile()`, you will need to update your code
35+
to use `Cypress.Commands.overwriteQuery('readFile', function() { ... })` rather
36+
than `Cypress.Commands.overwrite('readFile', () => { ... })`. For more details
37+
on overwriting queries, see the
38+
[Overwriting Existing Queries](/api/cypress-api/custom-queries#Overwriting-Existing-Queries).
6639

6740
## Migrating to Cypress 12.0
6841

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)