Skip to content

update examples to have them follow unsafe to chain conventions #6186

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/api/commands/blur.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ Pass in an options object to change the default behavior of `.blur`.
#### Blur the comment input

```javascript
cy.get('[name="comment"]').type('Nice Product!').blur()
cy.get('[name="comment"]').type('Nice Product!')
cy.get('[name="comment"]').blur()
```

### Options
Expand Down Expand Up @@ -140,7 +141,9 @@ events. Your best bet here is to keep Cypress focused when working on a test.
**_Blur a textarea after typing._**

```javascript
cy.get('[name="comment"]').focus().type('Nice Product!').blur()
cy.get('[name="comment"]').focus()
cy.get('[name="comment"]').type('Nice Product!')
cy.get('[name="comment"]').blur()
```

The commands above will display in the Command Log as:
Expand Down
9 changes: 6 additions & 3 deletions docs/api/commands/clear.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ An alias for [`.type('{selectall}{del}')`](/api/commands/type)

```javascript
cy.get('[type="text"]').clear() // Clear text input
cy.get('textarea').type('Hi!').clear() // Clear textarea
cy.get('textarea').type('Hi!')
cy.get('textarea').clear() // Clear textarea
cy.focused().clear() // Clear focused input/textarea
```

Expand Down Expand Up @@ -73,7 +74,8 @@ Pass in an options object to change the default behavior of `.clear()`.
#### Clear the input and type a new value

```javascript
cy.get('textarea').clear().type('Hello, World')
cy.get('textarea').clear()
cy.get('textarea').type('Hello, World')
```

## Notes
Expand Down Expand Up @@ -117,7 +119,8 @@ Please read the [`.type()`](/api/commands/type) documentation for more details.
**_Clear the input and type a new value_**

```javascript
cy.get('input[name="name"]').clear().type('Jane Lane')
cy.get('input[name="name"]').clear()
cy.get('input[name="name"]').type('Jane Lane')
```

The commands above will display in the Command Log as:
Expand Down
5 changes: 3 additions & 2 deletions docs/api/commands/focus.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ cy.get('[type="input"]').focus()
#### Focus, type, and blur a textarea

```javascript
// yields the <textarea> for further chaining
cy.get('textarea').focus().type('Nice Product!').blur()
cy.get('textarea').focus()
cy.get('textarea').type('Nice Product!')
cy.get('textarea').blur()
```

## Notes
Expand Down
17 changes: 8 additions & 9 deletions docs/api/commands/pause.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,14 @@ cy.get('button').should('not.be.disabled')
**_Pause and step through each `.click()` command_**

```javascript
cy.get('#action-canvas')
.click(80, 75)
.pause()
.click(170, 75)
.click(80, 165)
.click(100, 185)
.click(125, 190)
.click(150, 185)
.click(170, 165)
cy.get('#action-canvas').click(80, 75)
cy.pause()
cy.get('#action-canvas').click(170, 75)
cy.get('#action-canvas').click(80, 165)
cy.get('#action-canvas').click(100, 185)
cy.get('#action-canvas').click(125, 190)
cy.get('#action-canvas').click(150, 185)
cy.get('#action-canvas').click(170, 165)
```

The commands above will display in the Command Log as:
Expand Down
7 changes: 3 additions & 4 deletions docs/api/commands/trigger.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ To simulate drag and drop using jQuery UI sortable requires `pageX` and `pageY`
properties along with `which:1`.

```javascript
cy.get('[data-cy=draggable]')
.trigger('mousedown', { which: 1, pageX: 600, pageY: 100 })
.trigger('mousemove', { which: 1, pageX: 600, pageY: 600 })
.trigger('mouseup')
cy.get('[data-cy=draggable]').trigger('mousedown', { which: 1, pageX: 600, pageY: 100 })
cy.get('[data-cy=draggable]').trigger('mousemove', { which: 1, pageX: 600, pageY: 600 })
cy.get('[data-cy=draggable]').trigger('mouseup')
```

#### Drag and Drop
Expand Down
3 changes: 2 additions & 1 deletion docs/api/commands/type.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ cy.get('body').type(
// execute a SHIFT + click on the first <li>
// {release: false} is necessary so that
// SHIFT will not be released after the type command
cy.get('body').type('{shift}', { release: false }).get('li:first').click()
cy.get('body').type('{shift}', { release: false })
.get('li:first').click()
```

### Options
Expand Down
4 changes: 1 addition & 3 deletions docs/api/cypress-api/catalog-of-events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,13 @@ it('can modify the window prior to page load on all pages', () => {
cy
// window:before:load will be called here
.visit('/first/page')

.then((win) => {
// and here
win.location.href = '/second/page'
})

// and here
.get('a')
.click()
cy.get('a').click()
})
```

Expand Down
2 changes: 1 addition & 1 deletion docs/api/cypress-api/custom-commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Cypress.Commands.add('loginViaUi', (user) => {
cy.visit('/login')
cy.get('input[name=email]').type(user.email)
cy.get('input[name=password]').type(user.password)
cy.click('button#login')
cy.get('button#login').click()
cy.get('h1').contains(`Welcome back ${user.name}!`)
},
{
Expand Down
7 changes: 3 additions & 4 deletions docs/app/tooling/code-coverage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,9 @@ completed.
```js
it('adds and completes todos', () => {
-{cy.visit('/')::cy.mount(<AddTodo />)}-
cy.get('.new-todo')
.type('write code{enter}')
.type('write tests{enter}')
.type('deploy{enter}')
cy.get('.new-todo').type('write code{enter}')
cy.get('.new-todo').type('write tests{enter}')
cy.get('.new-todo').type('deploy{enter}')

cy.get('.todo').should('have.length', 3)

Expand Down
3 changes: 2 additions & 1 deletion docs/ui-coverage/guides/address-coverage-gaps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ Some gaps occur because elements are hidden or not rendered during tests. Update

```js
cy.get('[data-cy="dropdown-toggle"]').click() // Reveal hidden elements
cy.get('[data-cy="dropdown-item"]').should('be.visible').click()
cy.get('[data-cy="dropdown-item"]').should('be.visible')
cy.get('[data-cy="dropdown-item"]').click()
```

### Handle Dynamic Content
Expand Down