You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/testing/cypress.md
+30-1Lines changed: 30 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -222,9 +222,38 @@ The following shows an example:
222
222
cy.get('#foo')
223
223
// Once #foo is found the following:
224
224
.contains('Submit')
225
+
.click()
225
226
// ^ will continue to search for something that has text `Submit` and fail if it times out.
227
+
// ^ After it is found trigger a click on the HTML Node that contained the text `Submit`.
228
+
```
229
+
## Tip: Implicit assertion
230
+
Cypress has a concept of implicit assertion. These only kick in if a future command is erroring because of a previous command. E.g. The following will not error if there is no text with `Submit`:
231
+
232
+
```ts
233
+
cy.get('#foo')
234
+
// Once #foo is found the following:
235
+
.contains('Submit')
236
+
```
237
+
However the following will error at `contains` (after automatic retries of course) as nothing found can get `click`ed:
238
+
239
+
```ts
240
+
cy.get('#foo')
241
+
// Once #foo is found the following:
242
+
.contains('Submit')
226
243
.click()
227
-
// ^ will trigger a click on the HTML Node that contained the text `Submit`.
244
+
// ^ Error: #foo does not have anything that `contains` `'Submit'`
245
+
```
246
+
247
+
If you want to assert *use an explicit assertion* and don't rely on implicit assertions. e.g. instead of `contains` you would `cy.should('contain','Submit')` e.g.
0 commit comments