Skip to content

Commit e60a1e2

Browse files
committed
feat: replacing visit/mount directive with custom component
1 parent 9c97746 commit e60a1e2

18 files changed

+460
-228
lines changed

components/global/E2eOrCt.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<template>
2+
<code-group sync-group="e2e-ct">
3+
<code-block label="End-to-End Test" active>
4+
<slot name="e2e"></slot>
5+
</code-block>
6+
<code-block label="Component Test">
7+
<slot name="ct"></slot>
8+
</code-block>
9+
</code-group>
10+
</template>

content/api/commands/clock.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,25 +152,30 @@ cy.get('.timer').then(($timer) => {
152152

153153
#### Specify a now timestamp
154154

155-
:::visit-mount-test-example
155+
<e2e-or-ct>
156+
<template #e2e>
156157

157158
```js
159+
const now = new Date(2021, 3, 14) // month is 0-indexed
160+
161+
cy.clock(now)
158162
cy.visit('/index.html')
163+
cy.get('#date').should('have.value', '04/14/2021')
159164
```
160165

161-
```js
162-
cy.mount(<DatePicker id="date" />)
163-
```
166+
</template>
167+
<template #ct>
164168

165169
```js
166170
const now = new Date(2021, 3, 14) // month is 0-indexed
167171

168172
cy.clock(now)
169-
__VISIT_MOUNT_PLACEHOLDER__
173+
cy.mount(<DatePicker id="date" />)
170174
cy.get('#date').should('have.value', '04/14/2021')
171175
```
172176

173-
:::
177+
</template>
178+
</e2e-or-ct>
174179

175180
### Function names
176181

content/api/commands/fixture.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,29 +183,38 @@ cy.fixture('users').then((json) => {
183183
You can modify fixture data directly before visiting a URL or mounting a
184184
component that makes a network request to that URL.
185185

186-
:::visit-mount-test-example
186+
<e2e-or-ct>
187+
<template #e2e>
187188

188189
```js
190+
cy.fixture('user').then((user) => {
191+
user.firstName = 'Jane'
192+
cy.intercept('GET', '/users/1', user).as('getUser')
193+
})
194+
189195
cy.visit('/users')
196+
cy.wait('@getUser').then(({ request }) => {
197+
expect(request.body.firstName).to.eq('Jane')
198+
})
190199
```
191200

192-
```js
193-
cy.mount(<Users />)
194-
```
201+
</template>
202+
<template #ct>
195203

196204
```js
197205
cy.fixture('user').then((user) => {
198206
user.firstName = 'Jane'
199207
cy.intercept('GET', '/users/1', user).as('getUser')
200208
})
201209

202-
__VISIT_MOUNT_PLACEHOLDER__
210+
cy.mount(<Users />)
203211
cy.wait('@getUser').then(({ request }) => {
204212
expect(request.body.firstName).to.eq('Jane')
205213
})
206214
```
207215

208-
:::
216+
</template>
217+
</e2e-or-ct>
209218

210219
## Notes
211220

content/api/commands/viewport.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,33 @@ describe('Nav Menus', () => {
132132

133133
#### Dynamically test multiple viewports
134134

135-
:::visit-mount-test-example
135+
<e2e-or-ct>
136+
<template #e2e>
136137

137138
```js
138-
cy.visit('https://www.cypress.io')
139-
```
139+
const sizes = ['iphone-6', 'ipad-2', [1024, 768]]
140140

141-
```js
142-
cy.mount(<MyComponent />)
141+
describe('Logo', () => {
142+
sizes.forEach((size) => {
143+
// make assertions on the logo using
144+
// an array of different viewports
145+
it(`Should display logo on ${size} screen`, () => {
146+
if (Cypress._.isArray(size)) {
147+
cy.viewport(size[0], size[1])
148+
} else {
149+
cy.viewport(size)
150+
}
151+
152+
cy.visit('https://www.cypress.io')
153+
cy.get('#logo').should('be.visible')
154+
})
155+
})
156+
})
143157
```
144158

159+
</template>
160+
<template #ct>
161+
145162
```js
146163
const sizes = ['iphone-6', 'ipad-2', [1024, 768]]
147164

@@ -156,14 +173,15 @@ describe('Logo', () => {
156173
cy.viewport(size)
157174
}
158175

159-
__VISIT_MOUNT_PLACEHOLDER__
176+
cy.mount(<MyComponent />)
160177
cy.get('#logo').should('be.visible')
161178
})
162179
})
163180
})
164181
```
165182

166-
:::
183+
</template>
184+
</e2e-or-ct>
167185

168186
<DocsImage src="/img/api/viewport/loop-through-an-array-of-multiple-viewports.png" alt="Command Log of multiple viewports" ></DocsImage>
169187

content/api/commands/wait.md

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,38 @@ For a detailed explanation of aliasing,
104104

105105
#### Wait for a specific request to respond
106106

107-
:::visit-mount-test-example
107+
<e2e-or-ct>
108+
<template #e2e>
108109

109110
```js
111+
// Wait for the alias 'getAccount' to respond
112+
// without changing or stubbing its response
113+
cy.intercept('/accounts/*').as('getAccount')
110114
cy.visit('/accounts/123')
115+
cy.wait('@getAccount').then((interception) => {
116+
// we can now access the low level interception
117+
// that contains the request body,
118+
// response body, status, etc
119+
})
111120
```
112121

113-
```js
114-
cy.mount(<Account />)
115-
```
122+
</template>
123+
<template #ct>
116124

117125
```js
118126
// Wait for the alias 'getAccount' to respond
119127
// without changing or stubbing its response
120128
cy.intercept('/accounts/*').as('getAccount')
121-
__VISIT_MOUNT_PLACEHOLDER__
129+
cy.mount(<Account />)
122130
cy.wait('@getAccount').then((interception) => {
123131
// we can now access the low level interception
124132
// that contains the request body,
125133
// response body, status, etc
126134
})
127135
```
128136

129-
:::
137+
</template>
138+
</e2e-or-ct>
130139

131140
#### Wait automatically increments responses
132141

@@ -165,21 +174,33 @@ cy.get('#book-results').should('have.length', 1)
165174
When passing an array of aliases to `cy.wait()`, Cypress will wait for all
166175
requests to complete within the given `requestTimeout` and `responseTimeout`.
167176

168-
:::visit-mount-test-example
177+
<e2e-or-ct>
178+
<template #e2e>
169179

170180
```js
181+
cy.intercept('/users/*').as('getUsers')
182+
cy.intercept('/activities/*').as('getActivities')
183+
cy.intercept('/comments/*').as('getComments')
171184
cy.visit('/dashboard')
172-
```
173185

174-
```js
175-
cy.mount(<Dashboard />)
186+
cy.wait(['@getUsers', '@getActivities', '@getComments']).then(
187+
(interceptions) => {
188+
// interceptions will now be an array of matching requests
189+
// interceptions[0] <-- getUsers
190+
// interceptions[1] <-- getActivities
191+
// interceptions[2] <-- getComments
192+
}
193+
)
176194
```
177195

196+
</template>
197+
<template #ct>
198+
178199
```js
179200
cy.intercept('/users/*').as('getUsers')
180201
cy.intercept('/activities/*').as('getActivities')
181202
cy.intercept('/comments/*').as('getComments')
182-
__VISIT_MOUNT_PLACEHOLDER__
203+
cy.mount(<Dashboard />)
183204

184205
cy.wait(['@getUsers', '@getActivities', '@getComments']).then(
185206
(interceptions) => {
@@ -191,7 +212,8 @@ cy.wait(['@getUsers', '@getActivities', '@getComments']).then(
191212
)
192213
```
193214

194-
:::
215+
</template>
216+
</e2e-or-ct>
195217

196218
#### Using [`.spread()`](/api/commands/spread) to spread the array into multiple arguments.
197219

content/api/commands/window.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,28 @@ Pass in an options object to change the default behavior of `cy.window()`.
4040

4141
#### Yield the remote window object
4242

43-
:::visit-mount-test-example
43+
<e2e-or-ct>
44+
<template #e2e>
4445

4546
```js
4647
cy.visit('http://localhost:8080/app')
48+
cy.window().then((win) => {
49+
// win is the remote window
50+
})
4751
```
4852

49-
```js
50-
cy.mount(<MyComponent />)
51-
```
53+
</template>
54+
<template #ct>
5255

5356
```js
54-
__VISIT_MOUNT_PLACEHOLDER__
57+
cy.mount(<MyComponent />)
5558
cy.window().then((win) => {
5659
// win is the remote window
5760
})
5861
```
5962

60-
:::
63+
</template>
64+
</e2e-or-ct>
6165

6266
#### Check a custom property
6367

0 commit comments

Comments
 (0)