cypress 10.3.1 → 10.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/exec/open.js +6 -0
- package/mount-utils/CHANGELOG.md +0 -1
- package/mount-utils/README.md +7 -0
- package/package.json +10 -5
- package/react/CHANGELOG.md +0 -19
- package/react/README.md +28 -323
- package/react/dist/createMount.d.ts +30 -0
- package/react/dist/cypress-react.cjs.js +59 -78
- package/react/dist/cypress-react.esm-bundler.js +51 -74
- package/react/dist/getDisplayName.d.ts +1 -1
- package/react/dist/index.d.ts +2 -0
- package/react/dist/mount.d.ts +5 -141
- package/react/dist/types.d.ts +50 -0
- package/react/package.json +1 -5
- package/react18/dist/cypress-react.cjs.js +422 -0
- package/react18/dist/cypress-react.esm-bundler.js +394 -0
- package/react18/dist/index.d.ts +5 -0
- package/react18/package.json +59 -0
- package/types/cypress.d.ts +9 -0
- package/types/index.d.ts +1 -1
- package/types/{net-stubbing.ts → net-stubbing.d.ts} +0 -0
- package/vue/CHANGELOG.md +2 -17
- package/vue/README.md +17 -608
- package/vue/dist/@vue/test-utils/baseWrapper.d.ts +3 -1
- package/vue/dist/@vue/test-utils/config.d.ts +4 -2
- package/vue/dist/@vue/test-utils/emit.d.ts +1 -0
- package/vue/dist/@vue/test-utils/index.d.ts +2 -1
- package/vue/dist/@vue/test-utils/interfaces/wrapperLike.d.ts +2 -2
- package/vue/dist/@vue/test-utils/mount.d.ts +2 -0
- package/vue/dist/@vue/test-utils/stubs.d.ts +2 -6
- package/vue/dist/@vue/test-utils/types.d.ts +1 -1
- package/vue/dist/@vue/test-utils/vueWrapper.d.ts +2 -1
- package/vue/dist/cypress-vue.cjs.js +5379 -5090
- package/vue/dist/cypress-vue.esm-bundler.js +5380 -5091
- package/vue/dist/index.d.ts +1 -0
- package/vue/package.json +2 -2
- package/vue2/README.md +11 -627
- package/vue2/dist/cypress-vue2.browser.js +251 -260
- package/vue2/dist/cypress-vue2.cjs.js +250 -259
- package/vue2/dist/cypress-vue2.esm-bundler.js +248 -257
- package/react/dist/cypress-react.browser.js +0 -512
package/vue/dist/index.d.ts
CHANGED
@@ -29,6 +29,7 @@ declare const VueTestUtils: {
|
|
29
29
|
}>;
|
30
30
|
VueWrapper: typeof VueWrapper;
|
31
31
|
DOMWrapper: typeof _VueTestUtils.DOMWrapper;
|
32
|
+
BaseWrapper: typeof _VueTestUtils.BaseWrapper;
|
32
33
|
config: import("./@vue/test-utils/config").GlobalConfigOptions;
|
33
34
|
flushPromises: typeof _VueTestUtils.flushPromises;
|
34
35
|
createWrapperError: typeof _VueTestUtils.createWrapperError;
|
package/vue/package.json
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
"@rollup/plugin-node-resolve": "^11.1.1",
|
22
22
|
"@vitejs/plugin-vue": "2.3.1",
|
23
23
|
"@vue/compiler-sfc": "3.2.31",
|
24
|
-
"@vue/test-utils": "2.0.
|
24
|
+
"@vue/test-utils": "2.0.2",
|
25
25
|
"axios": "0.21.2",
|
26
26
|
"cypress": "0.0.0-development",
|
27
27
|
"debug": "^4.3.2",
|
@@ -31,7 +31,7 @@
|
|
31
31
|
"rollup-plugin-typescript2": "^0.29.0",
|
32
32
|
"tailwindcss": "1.1.4",
|
33
33
|
"typescript": "^4.2.3",
|
34
|
-
"vite": "
|
34
|
+
"vite": "3.0.3",
|
35
35
|
"vue": "3.2.31",
|
36
36
|
"vue-i18n": "9.0.0-rc.6",
|
37
37
|
"vue-router": "^4.0.0",
|
package/vue2/README.md
CHANGED
@@ -1,87 +1,20 @@
|
|
1
1
|
# @cypress/vue2
|
2
2
|
|
3
|
-
[
|
3
|
+
Mount Vue components in the open source [Cypress.io](https://www.cypress.io/) test runner **v7.0.0+**
|
4
4
|
|
5
|
-
[
|
6
|
-
|
7
|
-
> Browser-based Component Testing for Vue.js 2.x with the Open-Source [Cypress.io](https://www.cypress.io/) Test Runner ✌️🌲
|
8
|
-
>
|
9
|
-
**✨ New** We're growing the Cypress Community Discord. We have dedicated sections on Component Testing. 👉 [Join now](https://discord.com/invite/TmzTGUW) and let's chat!
|
10
|
-
|
11
|
-
**Jump to:** [Comparison](#comparison), [Blog posts](#blog-posts), Examples: [basic](#basic-examples), [advanced](#advanced-examples), [full](#full-examples), [external](#external-examples), [Code coverage](#code-coverage), [Development](#development)
|
12
|
-
|
13
|
-
### What is @cypress/vue2?
|
14
|
-
This package allows you to use the [Cypress](https://www.cypress.io/) test runner to mount and test your Vue 2 components within Cypress. It is built on top of the [Vue Test Utils](https://github.com/vuejs/vue-test-utils) package.
|
15
|
-
|
16
|
-
![Example component test](images/dynamic.gif)
|
17
|
-
|
18
|
-
### How is this different from Vue Test Utils?
|
19
|
-
It uses [Vue Test Utils](https://github.com/vuejs/vue-test-utils) under the hood. This is more of a replacement for node-based testing than it is replacing Vue Test Utils and its API. Instead of running your tests in node (using Jest or Mocha), the Cypress Component Testing Library runs each component in the **real browser** with full power of the Cypress Framework: [live GUI, full API, screen recording, CI support, cross-platform](https://www.cypress.io/features/). One benefit to using Cypress instead of a node-based runner is that limitations of Vue Test Utils in Node (e.g. manually awaiting Vue's internal event loop) are hidden from the user due to Cypress's retry-ability logic.
|
20
|
-
|
21
|
-
- If you like using `@testing-library/vue`, you can use `@testing-library/cypress` for the same `findBy`, `queryBy` commands, see one of the examples in the list below
|
5
|
+
> **Note:** This package is bundled with the `cypress` package and should not need to be installed separately. See the [Vue Component Testing Docs](https://docs.cypress.io/guides/component-testing/quickstart-vue#Configuring-Component-Testing) for mounting Vue components. Installing and importing `mount` from `@cypress/vue` should only be used for advanced use-cases.
|
22
6
|
|
23
7
|
### How is this different from @cypress/vue?
|
24
|
-
Cypress packages the current version of Vue under @cypress/vue, and older versions under separate package names. Use [@cypress/vue](cypress-vue
|
8
|
+
Cypress packages the current version of Vue under @cypress/vue, and older versions under separate package names. Use [@cypress/vue](https://github.com/cypress-io/cypress/tree/develop/npm/vue) if you're up to date, and this package if you're still using vue@2.
|
25
9
|
|
26
10
|
## Installation
|
27
11
|
|
28
12
|
- Requires Cypress v7.0.0 or later
|
29
13
|
- Requires [Node](https://nodejs.org/en/) version 12 or above
|
30
|
-
- Requires Vue 2.x. If you are using Vue 3.0.0 or later, you want [@cypress/vue](cypress-vue
|
31
|
-
- Supports webpack-based projects, vite in alpha, if you would like us to support another, please [create an issue](https://github.com/cypress-io/cypress/issues/new?assignees=&labels=npm:%20@cypress/vue2&template=3-feature.md) or, if an issue already exists subscribe to it.
|
32
|
-
|
33
|
-
Now you are ready to install.
|
34
|
-
|
35
|
-
### Manual Installation
|
36
|
-
|
37
|
-
Using [@cypress/webpack-dev-server](https://github.com/cypress-io/cypress-webpack-preprocessor#readme) and [vue-loader](https://github.com/vuejs/vue-loader).
|
38
|
-
|
39
|
-
```js
|
40
|
-
// cypress/plugins/index.js
|
41
|
-
const webpack = require('@cypress/webpack-dev-server')
|
42
|
-
const webpackOptions = {
|
43
|
-
module: {
|
44
|
-
rules: [
|
45
|
-
{
|
46
|
-
test: /\.vue$/,
|
47
|
-
loader: 'vue-loader',
|
48
|
-
},
|
49
|
-
],
|
50
|
-
},
|
51
|
-
}
|
52
|
-
|
53
|
-
const options = {
|
54
|
-
// send in the options from your webpack.config.js, so it works the same
|
55
|
-
// as your app's code
|
56
|
-
webpackOptions,
|
57
|
-
watchOptions: {},
|
58
|
-
}
|
14
|
+
- Requires Vue 2.x. If you are using Vue 3.0.0 or later, you want [@cypress/vue](https://github.com/cypress-io/cypress/tree/develop/npm/vue) instead.
|
59
15
|
|
60
|
-
|
61
|
-
|
62
|
-
}
|
63
|
-
```
|
64
|
-
|
65
|
-
Install dev dependencies
|
66
|
-
|
67
|
-
```shell
|
68
|
-
npm i -D @cypress/webpack-dev-server \
|
69
|
-
vue-loader vue-template-compiler css-loader
|
70
|
-
```
|
71
|
-
|
72
|
-
And write a test
|
73
|
-
|
74
|
-
```js
|
75
|
-
import Hello from '../../components/Hello.vue'
|
76
|
-
import { mountCallback } from '@cypress/vue2'
|
77
|
-
|
78
|
-
describe('Hello.vue', () => {
|
79
|
-
beforeEach(mountCallback(Hello))
|
80
|
-
|
81
|
-
it('shows hello', () => {
|
82
|
-
cy.contains('Hello World!')
|
83
|
-
})
|
84
|
-
})
|
16
|
+
```sh
|
17
|
+
npm i -D @cypress/vue2
|
85
18
|
```
|
86
19
|
|
87
20
|
## Usage and Examples
|
@@ -118,8 +51,6 @@ mount(Todo, {
|
|
118
51
|
})
|
119
52
|
```
|
120
53
|
|
121
|
-
See examples below for details.
|
122
|
-
|
123
54
|
### Global Vue Options
|
124
55
|
|
125
56
|
You can pass extensions (global components, mixins, modules to use)
|
@@ -131,541 +62,11 @@ the `options`.
|
|
131
62
|
- `mixin` (alias `mixins`) - list of global mixins, see [Mixins](cypress/component/basic/mixins) example
|
132
63
|
- `filters` - hash of global filters, see [Filters](cypress/component/basic/filters) example
|
133
64
|
|
134
|
-
|
65
|
+
## Compatibility
|
135
66
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
```html
|
141
|
-
<div id="app">
|
142
|
-
{{ message }}
|
143
|
-
</div>
|
144
|
-
```
|
145
|
-
|
146
|
-
```js
|
147
|
-
var app = new Vue({
|
148
|
-
el: '#app',
|
149
|
-
data() {
|
150
|
-
return { message: 'Hello Vue!' }
|
151
|
-
},
|
152
|
-
})
|
153
|
-
```
|
154
|
-
|
155
|
-
It shows the message when running in the browser
|
156
|
-
|
157
|
-
```
|
158
|
-
Hello Vue!
|
159
|
-
```
|
160
|
-
|
161
|
-
Let's test it in [Cypress.io][cypress.io] (for the current version see
|
162
|
-
[cypress/integration/spec.js](cypress/integration/spec.js)).
|
163
|
-
|
164
|
-
```js
|
165
|
-
import { mountCallback } from '@cypress/vue2'
|
166
|
-
|
167
|
-
describe('Declarative rendering', () => {
|
168
|
-
// Vue code from https://vuejs.org/v2/guide/#Declarative-Rendering
|
169
|
-
const template = `
|
170
|
-
<div id="app">
|
171
|
-
{{ message }}
|
172
|
-
</div>
|
173
|
-
`
|
174
|
-
|
175
|
-
const data = {
|
176
|
-
message: 'Hello Vue!',
|
177
|
-
}
|
178
|
-
|
179
|
-
// that's all you need to do
|
180
|
-
beforeEach(mountCallback({ template, data }))
|
181
|
-
|
182
|
-
it('shows hello', () => {
|
183
|
-
cy.contains('Hello Vue!')
|
184
|
-
})
|
185
|
-
|
186
|
-
it('changes message if data changes', () => {
|
187
|
-
// mounted Vue instance is available under Cypress.vue
|
188
|
-
Cypress.vue.message = 'Vue rocks!'
|
189
|
-
cy.contains('Vue rocks!')
|
190
|
-
})
|
191
|
-
})
|
192
|
-
```
|
193
|
-
|
194
|
-
Fire up Cypress test runner and have real browser (Electron, Chrome) load
|
195
|
-
Vue and mount your test code and be able to interact with the instance through
|
196
|
-
the reference `Cypress.vue.$data` and via GUI. The full power of the
|
197
|
-
[Cypress API](https://on.cypress.io/api) is available.
|
198
|
-
|
199
|
-
![Hello world tested](images/spec.png)
|
200
|
-
|
201
|
-
### list example
|
202
|
-
|
203
|
-
There is a list example next in the Vue docs.
|
204
|
-
|
205
|
-
```html
|
206
|
-
<div id="app-4">
|
207
|
-
<ol>
|
208
|
-
<li v-for="todo in todos">
|
209
|
-
{{ todo.text }}
|
210
|
-
</li>
|
211
|
-
</ol>
|
212
|
-
</div>
|
213
|
-
```
|
214
|
-
|
215
|
-
```js
|
216
|
-
var app4 = new Vue({
|
217
|
-
el: '#app-4',
|
218
|
-
data: {
|
219
|
-
todos: [
|
220
|
-
{ text: 'Learn JavaScript' },
|
221
|
-
{ text: 'Learn Vue' },
|
222
|
-
{ text: 'Build something awesome' },
|
223
|
-
],
|
224
|
-
},
|
225
|
-
})
|
226
|
-
```
|
227
|
-
|
228
|
-
Let's test it. Simple.
|
229
|
-
|
230
|
-
```js
|
231
|
-
import { mountCallback } from '@cypress/vue2'
|
232
|
-
|
233
|
-
describe('Declarative rendering', () => {
|
234
|
-
// List example from https://vuejs.org/v2/guide/#Declarative-Rendering
|
235
|
-
const template = `
|
236
|
-
<ol>
|
237
|
-
<li v-for="todo in todos">
|
238
|
-
{{ todo.text }}
|
239
|
-
</li>
|
240
|
-
</ol>
|
241
|
-
`
|
242
|
-
|
243
|
-
function data() {
|
244
|
-
return {
|
245
|
-
todos: [
|
246
|
-
{ text: 'Learn JavaScript' },
|
247
|
-
{ text: 'Learn Vue' },
|
248
|
-
{ text: 'Build something awesome' },
|
249
|
-
],
|
250
|
-
}
|
251
|
-
}
|
252
|
-
|
253
|
-
beforeEach(mountCallback({ template, data }))
|
254
|
-
|
255
|
-
it('shows 3 items', () => {
|
256
|
-
cy.get('li').should('have.length', 3)
|
257
|
-
})
|
258
|
-
|
259
|
-
it('can add an item', () => {
|
260
|
-
Cypress.vue.todos.push({ text: 'Test using Cypress' })
|
261
|
-
cy.get('li').should('have.length', 4)
|
262
|
-
})
|
263
|
-
})
|
264
|
-
```
|
265
|
-
|
266
|
-
![List tested](images/list-spec.png)
|
267
|
-
|
268
|
-
### Handling User Input
|
269
|
-
|
270
|
-
The next section in the Vue docs starts with [reverse message example](https://vuejs.org/v2/guide/#Handling-User-Input).
|
271
|
-
|
272
|
-
```html
|
273
|
-
<div id="app-5">
|
274
|
-
<p>{{ message }}</p>
|
275
|
-
<button @click="reverseMessage">Reverse Message</button>
|
276
|
-
</div>
|
277
|
-
```
|
278
|
-
|
279
|
-
```js
|
280
|
-
var app5 = new Vue({
|
281
|
-
el: '#app-5',
|
282
|
-
data: {
|
283
|
-
message: 'Hello Vue.js!',
|
284
|
-
},
|
285
|
-
methods: {
|
286
|
-
reverseMessage: function () {
|
287
|
-
this.message = this.message.split('').reverse().join('')
|
288
|
-
},
|
289
|
-
},
|
290
|
-
})
|
291
|
-
```
|
292
|
-
|
293
|
-
We can write the test the same way
|
294
|
-
|
295
|
-
```js
|
296
|
-
import { mountCallback } from '@cypress/vue2'
|
297
|
-
|
298
|
-
describe('Handling User Input', () => {
|
299
|
-
// Example from https://vuejs.org/v2/guide/#Handling-User-Input
|
300
|
-
const template = `
|
301
|
-
<div>
|
302
|
-
<p>{{ message }}</p>
|
303
|
-
<button @click="reverseMessage">Reverse Message</button>
|
304
|
-
</div>
|
305
|
-
`
|
306
|
-
|
307
|
-
function data() {
|
308
|
-
return { message: 'Hello Vue.js!' }
|
309
|
-
}
|
310
|
-
|
311
|
-
const methods = {
|
312
|
-
reverseMessage: function () {
|
313
|
-
this.message = this.message.split('').reverse().join('')
|
314
|
-
},
|
315
|
-
}
|
316
|
-
|
317
|
-
beforeEach(mountCallback({ template, data, methods }))
|
318
|
-
|
319
|
-
it('reverses text', () => {
|
320
|
-
cy.contains('Hello Vue')
|
321
|
-
cy.get('button').click()
|
322
|
-
cy.contains('!sj.euV olleH')
|
323
|
-
})
|
324
|
-
})
|
325
|
-
```
|
326
|
-
|
327
|
-
Take a look at the video of the test. When you hover over the `CLICK` step
|
328
|
-
the test runner is showing _before_ and _after_ DOM snapshots. Not only that,
|
329
|
-
the application is fully functioning, you can interact with the application
|
330
|
-
because it is really running!
|
331
|
-
|
332
|
-
![Reverse input](images/reverse-spec.gif)
|
333
|
-
|
334
|
-
<a name="component-example"/>
|
335
|
-
|
336
|
-
### Component example
|
337
|
-
|
338
|
-
Let us test a complex example. Let us test a [single file Vue component](https://vuejs.org/v2/guide/single-file-components.html). Here is the [Hello.vue](Hello.vue) file
|
339
|
-
|
340
|
-
```vue
|
341
|
-
<template>
|
342
|
-
<p>{{ greeting }} World!</p>
|
343
|
-
</template>
|
344
|
-
|
345
|
-
<script>
|
346
|
-
export default {
|
347
|
-
data() {
|
348
|
-
return {
|
349
|
-
greeting: 'Hello',
|
350
|
-
}
|
351
|
-
},
|
352
|
-
}
|
353
|
-
</script>
|
354
|
-
|
355
|
-
<style scoped>
|
356
|
-
p {
|
357
|
-
font-size: 2em;
|
358
|
-
text-align: center;
|
359
|
-
}
|
360
|
-
</style>
|
361
|
-
```
|
362
|
-
|
363
|
-
**note** to learn how to load Vue component files in Cypress, see
|
364
|
-
[Bundling](#bundling) section.
|
365
|
-
|
366
|
-
Do you want to interact with the component? Go ahead! Do you want
|
367
|
-
to have multiple components? No problem!
|
368
|
-
|
369
|
-
```js
|
370
|
-
import Hello from '../../components/Hello.vue'
|
371
|
-
import { mountCallback } from '@cypress/vue2'
|
372
|
-
describe('Several components', () => {
|
373
|
-
const template = `
|
374
|
-
<div>
|
375
|
-
<hello></hello>
|
376
|
-
<hello></hello>
|
377
|
-
<hello></hello>
|
378
|
-
</div>
|
379
|
-
`
|
380
|
-
const components = {
|
381
|
-
hello: Hello,
|
382
|
-
}
|
383
|
-
beforeEach(mountCallback({ template, components }))
|
384
|
-
|
385
|
-
it('greets the world 3 times', () => {
|
386
|
-
cy.get('p').should('have.length', 3)
|
387
|
-
})
|
388
|
-
})
|
389
|
-
```
|
390
|
-
|
391
|
-
### Spying example
|
392
|
-
|
393
|
-
Button counter component is used in several Vue doc examples
|
394
|
-
|
395
|
-
```vue
|
396
|
-
<template>
|
397
|
-
<button @click="incrementCounter">{{ counter }}</button>
|
398
|
-
</template>
|
399
|
-
|
400
|
-
<script>
|
401
|
-
export default {
|
402
|
-
data() {
|
403
|
-
return {
|
404
|
-
counter: 0,
|
405
|
-
}
|
406
|
-
},
|
407
|
-
|
408
|
-
methods: {
|
409
|
-
incrementCounter: function () {
|
410
|
-
this.counter += 1
|
411
|
-
this.$emit('increment')
|
412
|
-
},
|
413
|
-
},
|
414
|
-
}
|
415
|
-
</script>
|
416
|
-
|
417
|
-
<style scoped>
|
418
|
-
button {
|
419
|
-
margin: 5px 10px;
|
420
|
-
padding: 5px 10px;
|
421
|
-
border-radius: 3px;
|
422
|
-
}
|
423
|
-
</style>
|
424
|
-
```
|
425
|
-
|
426
|
-
Let us test it - how do we ensure the event is emitted when the button is clicked?
|
427
|
-
Simple - let us spy on the event, [spying and stubbing is built into Cypress](https://on.cypress.io/stubs-spies-and-clocks)
|
428
|
-
|
429
|
-
```js
|
430
|
-
import ButtonCounter from '../../components/ButtonCounter.vue'
|
431
|
-
import { mountCallback } from '@cypress/vue2'
|
432
|
-
|
433
|
-
describe('ButtonCounter', () => {
|
434
|
-
beforeEach(mountCallback(ButtonCounter))
|
435
|
-
|
436
|
-
it('starts with zero', () => {
|
437
|
-
cy.contains('button', '0')
|
438
|
-
})
|
439
|
-
|
440
|
-
it('increments the counter on click', () => {
|
441
|
-
cy.get('button').click().click().click().contains('3')
|
442
|
-
})
|
443
|
-
|
444
|
-
it('emits "increment" event on click', () => {
|
445
|
-
const spy = cy.spy()
|
446
|
-
Cypress.vue.$on('increment', spy)
|
447
|
-
cy.get('button')
|
448
|
-
.click()
|
449
|
-
.click()
|
450
|
-
.then(() => {
|
451
|
-
expect(spy).to.be.calledTwice
|
452
|
-
})
|
453
|
-
})
|
454
|
-
})
|
455
|
-
```
|
456
|
-
|
457
|
-
The component is really updating the counter in response to the click
|
458
|
-
and is emitting an event.
|
459
|
-
|
460
|
-
![Spying test](images/spy-spec.png)
|
461
|
-
|
462
|
-
[cypress.io]: https://www.cypress.io/
|
463
|
-
|
464
|
-
<a name="xhr-spying-stubbing"/>
|
465
|
-
|
466
|
-
### XHR spying and stubbing
|
467
|
-
|
468
|
-
The mount function automatically wraps XMLHttpRequest giving you an ability to intercept XHR requests your component might do. For full documentation see [Network Requests](https://on.cypress.io/network-requests). In this repo see [components/AjaxList.vue](components/AjaxList.vue) and the corresponding tests [cypress/integration/ajax-list-spec.js](cypress/integration/ajax-list-spec.js).
|
469
|
-
|
470
|
-
```js
|
471
|
-
// component use axios to get list of users
|
472
|
-
created() {
|
473
|
-
axios.get(`https://jsonplaceholder.cypress.io/users?_limit=3`)
|
474
|
-
.then(response => {
|
475
|
-
// JSON responses are automatically parsed.
|
476
|
-
this.users = response.data
|
477
|
-
})
|
478
|
-
}
|
479
|
-
// test can observe, return mock data, delay and a lot more
|
480
|
-
beforeEach(mountCallback(AjaxList))
|
481
|
-
it('can inspect real data in XHR', () => {
|
482
|
-
cy.server()
|
483
|
-
cy.route('/users?_limit=3').as('users')
|
484
|
-
cy.wait('@users').its('response.body').should('have.length', 3)
|
485
|
-
})
|
486
|
-
it('can display mock XHR response', () => {
|
487
|
-
cy.server()
|
488
|
-
const users = [{id: 1, name: 'foo'}]
|
489
|
-
cy.route('GET', '/users?_limit=3', users).as('users')
|
490
|
-
cy.get('li').should('have.length', 1)
|
491
|
-
.first().contains('foo')
|
492
|
-
})
|
493
|
-
```
|
494
|
-
|
495
|
-
<a name="spying-window-alert"/>
|
496
|
-
|
497
|
-
### Spying on `window.alert`
|
498
|
-
|
499
|
-
Calls to `window.alert` are automatically recorded, but do not show up. Instead you can spy on them, see [AlertMessage.vue](components/AlertMessage.vue) and its test [cypress/integration/alert-spec.js](cypress/integration/alert-spec.js)
|
500
|
-
|
501
|
-
## Comparison
|
502
|
-
|
503
|
-
<!-- prettier-ignore-start -->
|
504
|
-
Feature | Vue Test Utils or @testing-library/vue | Cypress + `@cypress/vue2`
|
505
|
-
--- | --- | ---
|
506
|
-
Test runs in real browser | ❌ | ✅
|
507
|
-
Uses full mount | ❌ | ✅
|
508
|
-
Test speed | 🏎 | as fast as the app works in the browser
|
509
|
-
Test can use additional plugins | maybe | use any [Cypress plugin](https://on.cypress.io/plugins)
|
510
|
-
Test can interact with component | synthetic limited API | use any [Cypress command](https://on.cypress.io/api)
|
511
|
-
Test can be debugged | via terminal and Node debugger | use browser DevTools
|
512
|
-
Built-in time traveling debugger | ❌ | Cypress time traveling debugger
|
513
|
-
Re-run tests on file or test change | ✅ | ✅
|
514
|
-
Test output on CI | terminal | terminal, screenshots, videos
|
515
|
-
Tests can be run in parallel | ✅ | ✅ via [parallelization](https://on.cypress.io/parallelization)
|
516
|
-
Test against interface | if using `@testing-library/vue` | ✅ and can use `@testing-library/cypress`
|
517
|
-
Spying and mocking | Jest mocks | Sinon library
|
518
|
-
Code coverage | ✅ | ✅
|
519
|
-
<!-- prettier-ignore-end -->
|
520
|
-
|
521
|
-
## Examples
|
522
|
-
|
523
|
-
```js
|
524
|
-
// components/HelloWorld.spec.js
|
525
|
-
import { mount } from '@cypress/vue2'
|
526
|
-
import { HelloWorld } from './HelloWorld.vue'
|
527
|
-
describe('HelloWorld component', () => {
|
528
|
-
it('works', () => {
|
529
|
-
mount(HelloWorld)
|
530
|
-
// now use standard Cypress commands
|
531
|
-
cy.contains('Hello World!').should('be.visible')
|
532
|
-
})
|
533
|
-
})
|
534
|
-
```
|
535
|
-
|
536
|
-
### Basic examples
|
537
|
-
|
538
|
-
<!-- prettier-ignore-start -->
|
539
|
-
Spec | Description
|
540
|
-
--- | ---
|
541
|
-
[Components](cypress/component/basic/components) | Registers global components to use
|
542
|
-
[Filters](cypress/component/basic/filters) | Registering global filters
|
543
|
-
[Hello](cypress/component/basic/hello) | Testing examples from Vue2 cookbook
|
544
|
-
[Mixins](cypress/component/basic/mixins) | Registering Vue mixins
|
545
|
-
[Plugins](cypress/component/basic/plugins) | Loading additional plugins
|
546
|
-
[Props](cypress/component/basic/props) | Pass props to the component during mount
|
547
|
-
[Slots](cypress/component/basic/slots) | Passing slots and scopedSlots to the component
|
548
|
-
[Small examples](cypress/component/basic/small-examples) | A few small examples testing forms, buttons
|
549
|
-
<!-- prettier-ignore-end -->
|
550
|
-
|
551
|
-
### Advanced examples
|
552
|
-
|
553
|
-
<!-- prettier-ignore-start -->
|
554
|
-
Spec | Description
|
555
|
-
--- | ---
|
556
|
-
[access-component](cypress/component/advanced/access-component) | Access the mounted component directly from test
|
557
|
-
[i18n](cypress/component/advanced/i18n) | Testing component that uses [Vue I18n](https://kazupon.github.io/vue-i18n/) plugin
|
558
|
-
[mocking-axios](cypress/component/advanced/mocking-axios) | Mocking 3rd party CommonJS modules like `axios`
|
559
|
-
[mocking-fetch](cypress/component/advanced/mocking-fetch) | Mocking `window.fetch` to stub responses and test the UI
|
560
|
-
[fetch-polyfill](ypress/component/advanced/fetch-polyfill) | Using experimental `fetch` polyfill to spy on / stub those Ajax requests using regular Cypress network methods
|
561
|
-
[mocking-components](cypress/component/advanced/mocking-components) | Mocking locally registered child components during tests
|
562
|
-
[mocking-imports](cypress/component/advanced/mocking-imports) | Stub ES6 imports from the tests
|
563
|
-
[render-functions](cypress/component/advanced/render-functions) | Mounting components with a [render function](https://www.tutorialandexample.com/vue-js-render-functions/)
|
564
|
-
<!-- prettier-ignore-end -->
|
565
|
-
|
566
|
-
### Full examples
|
567
|
-
|
568
|
-
We have several subfolders in [examples](examples) folder.
|
569
|
-
|
570
|
-
<!-- prettier-ignore-start -->
|
571
|
-
Folder Name | Description
|
572
|
-
--- | ---
|
573
|
-
[cli](examples/cli) | An example app scaffolded using Vue CLI and the component testing added using `vue add cypress-experimental` command.
|
574
|
-
<!-- prettier-ignore-end -->
|
575
|
-
|
576
|
-
### External examples
|
577
|
-
|
578
|
-
<!-- prettier-ignore-start -->
|
579
|
-
Repo | Description
|
580
|
-
--- | ---
|
581
|
-
[vue-component-test-example](https://github.com/bahmutov/vue-component-test-example) | Scaffolded Vue CLI v3 project with added component tests, read [Write Your First Vue Component Test](https://glebbahmutov.com/blog/first-vue-component-test/).
|
582
|
-
<!-- prettier-ignore-end -->
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
## Code coverage
|
587
|
-
|
588
|
-
This plugin uses `babel-plugin-istanbul` to automatically instrument `.js` and `.vue` files and generates the code coverage report using dependency [cypress-io/code-coverage](https://github.com/cypress-io/code-coverage) (included). The output reports are saved in the folder "coverage" at the end of the test run.
|
589
|
-
|
590
|
-
If you want to disable code coverage instrumentation and reporting, use `--env coverage=false` or `CYPRESS_coverage=false` or set in your `cypress.json` file
|
591
|
-
|
592
|
-
```json
|
593
|
-
{
|
594
|
-
"env": {
|
595
|
-
"coverage": false
|
596
|
-
}
|
597
|
-
}
|
598
|
-
```
|
599
|
-
|
600
|
-
**Note ⚠️:** if the component `.vue` file does not have a `<script>` section, it will not have any code coverage information.
|
601
|
-
|
602
|
-
## What happened to cypress-vue-unit-test?
|
603
|
-
|
604
|
-
We were in the middle of moving into the Cypress NPM org, so any references to `cypress-vue-unit-test` should be switched to `@cypress/vue`. Once complete, the old repository will be archived.
|
605
|
-
|
606
|
-
## Development
|
607
|
-
|
608
|
-
To see all local tests, install dependencies, build the code and open Cypress using the open-ct command
|
609
|
-
|
610
|
-
```sh
|
611
|
-
yarn install
|
612
|
-
yarn workspace @cypress/vue build
|
613
|
-
```
|
614
|
-
|
615
|
-
The build is done using `rollup`. It bundles all files from [src](src) to the `dist` folder. You can then run component tests by opening Cypress
|
616
|
-
|
617
|
-
```sh
|
618
|
-
# cypress open-ct
|
619
|
-
yarn workspace @cypress/vue cy:open
|
620
|
-
```
|
621
|
-
|
622
|
-
Larger tests that use full application and run on CI (see [circle.yml](circle.yml)) are located in the folder [examples](examples).
|
623
|
-
|
624
|
-
### Debugging
|
625
|
-
|
626
|
-
Run Cypress with environment variable
|
627
|
-
|
628
|
-
```
|
629
|
-
DEBUG=@cypress/vue2
|
630
|
-
```
|
631
|
-
|
632
|
-
If some deeply nested objects are abbreviated and do not print fully, set the maximum logging depth
|
633
|
-
|
634
|
-
```
|
635
|
-
DEBUG=@cypress/vue2 DEBUG_DEPTH=10
|
636
|
-
```
|
637
|
-
|
638
|
-
## Related info
|
639
|
-
|
640
|
-
- [Testing Vue web applications with Vuex data store & REST backend](https://www.cypress.io/blog/2017/11/28/testing-vue-web-application-with-vuex-data-store-and-rest-backend/)
|
641
|
-
- [Why Cypress?](https://on.cypress.io/why-cypress)
|
642
|
-
- [Cypress API](https://on.cypress.io/api)
|
643
|
-
- [Learn TDD in Vue](https://learntdd.in/vue)
|
644
|
-
- [@cypress/vue vs vue-test-utils](https://codingitwrong.com/2018/03/04/comparing-vue-component-testing-tools.html)
|
645
|
-
|
646
|
-
## Blog posts
|
647
|
-
|
648
|
-
- [Write Your First Vue Component Test](https://glebbahmutov.com/blog/first-vue-component-test/)
|
649
|
-
|
650
|
-
## Test adapters for other frameworks
|
651
|
-
|
652
|
-
- [@cypress/react](https://github.com/cypress-io/@cypress/react)
|
653
|
-
- [cypress-cycle-unit-test](https://github.com/bahmutov/cypress-cycle-unit-test)
|
654
|
-
- [cypress-svelte-unit-test](https://github.com/bahmutov/cypress-svelte-unit-test)
|
655
|
-
- [@cypress/angular](https://github.com/bahmutov/@cypress/angular)
|
656
|
-
- [cypress-hyperapp-unit-test](https://github.com/bahmutov/cypress-hyperapp-unit-test)
|
657
|
-
- [cypress-angularjs-unit-test](https://github.com/bahmutov/cypress-angularjs-unit-test)
|
658
|
-
|
659
|
-
## Maintainers
|
660
|
-
|
661
|
-
The Cypress.io Component Testing Team
|
662
|
-
|
663
|
-
- [Jessica Sachs](https://github.com/jessicasachs) (Current Maintainer, [Vue Test Utils](https://github.com/vuejs/vue-test-utils) Maintainer)
|
664
|
-
- [Lachlan Miller](https://github.com/lmiller1990) (Current Maintainer, [Vue Test Utils](https://github.com/vuejs/vue-test-utils) Maintainer)
|
665
|
-
- [Bart Ledoux](https://github.com/elevatebart) (Current Maintainer, [Vue Styleguidist](https://github.com/vue-styleguidist/vue-styleguidist) Maintainer)
|
666
|
-
- [Gleb Bahmutov](https://github.com/bahmutov) (Original Author, Current Maintainer of [@cypress/react](https://github.com//cypress-io/@cypress/react))
|
667
|
-
|
668
|
-
Support: if you find any problems with this module, [tweet](https://twitter.com/_jessicasachs) / [open issue](https://github.com/cypress-io/cypress/issues) on Github
|
67
|
+
| @cypress/vue2 | cypress |
|
68
|
+
| ------------- | ------- |
|
69
|
+
| >= v1 | >= v10 |
|
669
70
|
|
670
71
|
## License
|
671
72
|
|
@@ -673,21 +74,4 @@ Support: if you find any problems with this module, [tweet](https://twitter.com/
|
|
673
74
|
|
674
75
|
This project is licensed under the terms of the [MIT license](/LICENSE).
|
675
76
|
|
676
|
-
## Changelog
|
677
|
-
|
678
|
-
[Changelog](./CHANGELOG.md)
|
679
|
-
|
680
|
-
## Badges
|
681
|
-
|
682
|
-
Let the world know your project is using Cypress.io to test with this cool badge
|
683
|
-
|
684
|
-
[![Cypress.io](https://img.shields.io/badge/tested%20with-Cypress-04C38E.svg)](https://www.cypress.io/)
|
685
|
-
|
686
|
-
[npm-icon]: https://nodei.co/npm/@cypress/vue.svg?downloads=true
|
687
|
-
[npm-url]: https://npmjs.org/package/@cypress/vue2
|
688
|
-
[cypress-vue-npm-url]: https://www.npmjs.com/package/@cypress/vue
|
689
|
-
[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
|
690
|
-
[semantic-url]: https://github.com/semantic-release/semantic-release
|
691
|
-
[cypress-badge]: https://img.shields.io/badge/cypress.io-tests-green.svg?style=flat-square
|
692
|
-
[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg
|
693
|
-
[renovate-app]: https://renovateapp.com/
|
77
|
+
## [Changelog](./CHANGELOG.md)
|