Skip to content

Commit 33ce7c1

Browse files
update examples to have them follow unsafe to chain conventions (#6186)
* update examples to have them follow unsafe to chain conventions * fix more instances of unsafe-to-chain * break out trigger * update another example * lint
1 parent 062bd77 commit 33ce7c1

File tree

10 files changed

+43
-31
lines changed

10 files changed

+43
-31
lines changed

docs/api/commands/blur.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ Pass in an options object to change the default behavior of `.blur`.
7474
#### Blur the comment input
7575

7676
```javascript
77-
cy.get('[name="comment"]').type('Nice Product!').blur()
77+
cy.get('[name="comment"]').type('Nice Product!')
78+
cy.get('[name="comment"]').blur()
7879
```
7980

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

142143
```javascript
143-
cy.get('[name="comment"]').focus().type('Nice Product!').blur()
144+
cy.get('[name="comment"]').focus()
145+
cy.get('[name="comment"]').type('Nice Product!')
146+
cy.get('[name="comment"]').blur()
144147
```
145148

146149
The commands above will display in the Command Log as:

docs/api/commands/clear.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ An alias for [`.type('{selectall}{del}')`](/api/commands/type)
3333

3434
```javascript
3535
cy.get('[type="text"]').clear() // Clear text input
36-
cy.get('textarea').type('Hi!').clear() // Clear textarea
36+
cy.get('textarea').type('Hi!')
37+
cy.get('textarea').clear() // Clear textarea
3738
cy.focused().clear() // Clear focused input/textarea
3839
```
3940

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

7576
```javascript
76-
cy.get('textarea').clear().type('Hello, World')
77+
cy.get('textarea').clear()
78+
cy.get('textarea').type('Hello, World')
7779
```
7880

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

119121
```javascript
120-
cy.get('input[name="name"]').clear().type('Jane Lane')
122+
cy.get('input[name="name"]').clear()
123+
cy.get('input[name="name"]').type('Jane Lane')
121124
```
122125

123126
The commands above will display in the Command Log as:

docs/api/commands/focus.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ cy.get('[type="input"]').focus()
6565
#### Focus, type, and blur a textarea
6666

6767
```javascript
68-
// yields the <textarea> for further chaining
69-
cy.get('textarea').focus().type('Nice Product!').blur()
68+
cy.get('textarea').focus()
69+
cy.get('textarea').type('Nice Product!')
70+
cy.get('textarea').blur()
7071
```
7172

7273
## Notes

docs/api/commands/pause.mdx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,14 @@ cy.get('button').should('not.be.disabled')
9595
**_Pause and step through each `.click()` command_**
9696

9797
```javascript
98-
cy.get('#action-canvas')
99-
.click(80, 75)
100-
.pause()
101-
.click(170, 75)
102-
.click(80, 165)
103-
.click(100, 185)
104-
.click(125, 190)
105-
.click(150, 185)
106-
.click(170, 165)
98+
cy.get('#action-canvas').click(80, 75)
99+
cy.pause()
100+
cy.get('#action-canvas').click(170, 75)
101+
cy.get('#action-canvas').click(80, 165)
102+
cy.get('#action-canvas').click(100, 185)
103+
cy.get('#action-canvas').click(125, 190)
104+
cy.get('#action-canvas').click(150, 185)
105+
cy.get('#action-canvas').click(170, 165)
107106
```
108107

109108
The commands above will display in the Command Log as:

docs/api/commands/trigger.mdx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,17 @@ To simulate drag and drop using jQuery UI sortable requires `pageX` and `pageY`
129129
properties along with `which:1`.
130130

131131
```javascript
132-
cy.get('[data-cy=draggable]')
133-
.trigger('mousedown', { which: 1, pageX: 600, pageY: 100 })
134-
.trigger('mousemove', { which: 1, pageX: 600, pageY: 600 })
135-
.trigger('mouseup')
132+
cy.get('[data-cy=draggable]').trigger('mousedown', {
133+
which: 1,
134+
pageX: 600,
135+
pageY: 100,
136+
})
137+
cy.get('[data-cy=draggable]').trigger('mousemove', {
138+
which: 1,
139+
pageX: 600,
140+
pageY: 600,
141+
})
142+
cy.get('[data-cy=draggable]').trigger('mouseup')
136143
```
137144

138145
#### Drag and Drop

docs/api/commands/viewport.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ cy.viewport(320, 480)
305305

306306
// the navbar should have collapse since our screen is smaller
307307
cy.get('#navbar').should('not.be.visible')
308-
cy.get('.navbar-toggle').should('be.visible').click()
308+
cy.get('.navbar-toggle').should('be.visible')
309+
cy.get('.navbar-toggle').click()
309310
cy.get('.nav').find('a').should('be.visible')
310311
```
311312

docs/api/cypress-api/catalog-of-events.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,13 @@ it('can modify the window prior to page load on all pages', () => {
344344
cy
345345
// window:before:load will be called here
346346
.visit('/first/page')
347-
348347
.then((win) => {
349348
// and here
350349
win.location.href = '/second/page'
351350
})
352351

353-
// and here
354-
.get('a')
355-
.click()
352+
// and here
353+
cy.get('a').click()
356354
})
357355
```
358356

docs/api/cypress-api/custom-commands.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ Cypress.Commands.add('loginViaUi', (user) => {
196196
cy.visit('/login')
197197
cy.get('input[name=email]').type(user.email)
198198
cy.get('input[name=password]').type(user.password)
199-
cy.click('button#login')
199+
cy.get('button#login').click()
200200
cy.get('h1').contains(`Welcome back ${user.name}!`)
201201
},
202202
{

docs/app/tooling/code-coverage.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,9 @@ completed.
388388
```js
389389
it('adds and completes todos', () => {
390390
-{cy.visit('/')::cy.mount(<AddTodo />)}-
391-
cy.get('.new-todo')
392-
.type('write code{enter}')
393-
.type('write tests{enter}')
394-
.type('deploy{enter}')
391+
cy.get('.new-todo').type('write code{enter}')
392+
cy.get('.new-todo').type('write tests{enter}')
393+
cy.get('.new-todo').type('deploy{enter}')
395394

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

docs/ui-coverage/guides/address-coverage-gaps.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ Some gaps occur because elements are hidden or not rendered during tests. Update
6969

7070
```js
7171
cy.get('[data-cy="dropdown-toggle"]').click() // Reveal hidden elements
72-
cy.get('[data-cy="dropdown-item"]').should('be.visible').click()
72+
cy.get('[data-cy="dropdown-item"]').should('be.visible')
73+
cy.get('[data-cy="dropdown-item"]').click()
7374
```
7475

7576
### Handle Dynamic Content

0 commit comments

Comments
 (0)