-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Queries, Detached DOM, and Retry-Ability #4835
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 all commits
14849d5
8268e5c
d5d0924
71a0e59
e3ffecb
a5c478c
8f05308
8ef6f86
7ae0bc0
299a226
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,20 @@ title: blur | |
|
||
Blur a focused element. | ||
|
||
It is [unsafe](/guides/core-concepts/retry-ability#Only-queries-are-retried) to | ||
chain further commands that rely on the subject after `.blur()`. | ||
|
||
<Alert type="warning"> | ||
|
||
This element must currently be in focus. If you want to ensure an element is | ||
focused before blurring, try using [`.focus()`](/api/commands/focus) before | ||
`.blur()`. | ||
|
||
```javascript | ||
cy.get('button').as('btn').focus() | ||
cy.get('@btn').blur() | ||
``` | ||
|
||
</Alert> | ||
|
||
## Syntax | ||
|
@@ -24,8 +32,8 @@ focused before blurring, try using [`.focus()`](/api/commands/focus) before | |
**<Icon name="check-circle" color="green"></Icon> Correct Usage** | ||
|
||
```javascript | ||
cy.get('[type="email"]').type('[email protected]').blur() // Blur email input | ||
cy.get('[tabindex="1"]').focus().blur() // Blur el with tabindex | ||
cy.get('[type="email"]').blur() // Blur email input | ||
cy.get('[tabindex="1"]').blur() // Blur el with tabindex | ||
``` | ||
|
||
**<Icon name="exclamation-triangle" color="red"></Icon> Incorrect Usage** | ||
|
@@ -49,8 +57,9 @@ Pass in an options object to change the default behavior of `.blur`. | |
|
||
### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management) | ||
|
||
<List><li>`.blur()` yields the same subject it was given from the previous | ||
command.</li></List> | ||
- `.blur()` yields the same subject it was given. | ||
- It is [unsafe](/guides/core-concepts/retry-ability#Only-queries-are-retried) | ||
to chain further commands that rely on the subject after `.blur()`. | ||
|
||
## Examples | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,9 @@ title: clear | |||||
|
||||||
Clear the value of an `input` or `textarea`. | ||||||
|
||||||
It is [unsafe](/guides/core-concepts/retry-ability#Only-queries-are-retried) to | ||||||
chain further commands that rely on the subject after `.clear()`. | ||||||
|
||||||
<Alert type="info"> | ||||||
|
||||||
An alias for [`.type('{selectall}{backspace}')`](/api/commands/type) | ||||||
|
@@ -52,8 +55,9 @@ Pass in an options object to change the default behavior of `.clear()`. | |||||
|
||||||
### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management) | ||||||
|
||||||
<List><li>`.clear()` yields the same subject it was given from the previous | ||||||
command.</li></List> | ||||||
- `.clear()` yields the same subject it was given. | ||||||
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. why drop
Suggested change
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. "From the previous command, query or assertion" is pretty verbose, and I don't think it actually adds any clarity. Assertions usually don't change the subject, but they can! So even before queries, this wasn't quite accurate. |
||||||
- It is [unsafe](/guides/core-concepts/retry-ability#Only-queries-are-retried) | ||||||
to chain further commands that rely on the subject after `.clear()`. | ||||||
|
||||||
## Examples | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,8 +41,7 @@ Pass in an options object to change the default behavior of `cy.clearCookies()`. | |
|
||
### Yields [<Icon name="question-circle"/>](/guides/core-concepts/introduction-to-cypress#Subject-Management) | ||
|
||
<List><li>`cy.clearCookies()` yields `null`.</li><li>`cy.clearCookies()` cannot | ||
be chained further.</li></List> | ||
BlueWinds marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- `cy.clearCookies()` yields `null`. | ||
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. Is clearCookies a query or a command? 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. Command. Also not sure it needs to be called out in the 'Yields' header though - it yields null, that's kind of the end of it. 🤷♀️ 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. curiosity question, if it yields null how can you continue to chain off it? 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. Showed an example in a comment here - #4835 (comment) The problem is that "parent" and "child" commands do not work the way you expect them to from the name.
This is all existing behavior from Cy1-11, covered by our own tests - the docs have just never explained it clearly. 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.
Seven parent commands chained together. Our own tests do this all the time, as do our example repos. Forcing parents to actually be parents or disallowing chaining after a command that returns 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. The reason we use the term "yields" and not "returns" is because it's stating which subject is passed to the next command, not what is returned from the command. All commands return a chainer object that allows chaining further commands. While we do indeed use a lot of unnecessary chaining in our tests, there's at least one legitimate use for chaining after a command that yields cy.clearCookies().then(() => {
// do something after clearing the cookies has completed
}) |
||
|
||
## Examples | ||
|
||
|
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.
quick preview pass through - this should be an action command correct?
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.
https://docs.cypress.io/api/commands/blur#Actionability