|
13 | 13 | Requires [Node](https://nodejs.org/en/) version 6 or above. |
14 | 14 |
|
15 | 15 | ```sh |
16 | | -npm install --save cypress-vue-unit-test |
| 16 | +npm install --save-dev cypress-vue-unit-test |
17 | 17 | ``` |
18 | 18 |
|
19 | 19 | ## Use |
20 | 20 |
|
| 21 | +Take a look at the first Vue v2 example: |
| 22 | +[Declarative Rendering](https://vuejs.org/v2/guide/#Declarative-Rendering). |
| 23 | +The code is pretty simple |
| 24 | + |
| 25 | +```html |
| 26 | +<div id="app"> |
| 27 | + {{ message }} |
| 28 | +</div> |
| 29 | +``` |
| 30 | +```js |
| 31 | +var app = new Vue({ |
| 32 | + el: '#app', |
| 33 | + data: { |
| 34 | + message: 'Hello Vue!' |
| 35 | + } |
| 36 | +}) |
| 37 | +``` |
| 38 | +It shows the message when running in the browser |
| 39 | +``` |
| 40 | +Hello Vue! |
| 41 | +``` |
| 42 | + |
| 43 | +Let's test it in [Cypress.io][cypress.io] (for the current version see |
| 44 | +[cypress/integration/spec.js](cypress/integration/spec.js)). |
| 45 | + |
| 46 | +```js |
| 47 | +const mountVue = require('cypress-vue-unit-test') |
| 48 | + |
| 49 | +/* eslint-env mocha */ |
| 50 | +describe('Declarative rendering', () => { |
| 51 | + // Vue code from https://vuejs.org/v2/guide/#Declarative-Rendering |
| 52 | + const template = ` |
| 53 | + <div id="app"> |
| 54 | + {{ message }} |
| 55 | + </div> |
| 56 | + ` |
| 57 | + |
| 58 | + const data = { |
| 59 | + message: 'Hello Vue!' |
| 60 | + } |
| 61 | + |
| 62 | + // that's all you need to do |
| 63 | + beforeEach(mountVue({ template, data })) |
| 64 | + |
| 65 | + it('shows hello', () => { |
| 66 | + cy.contains('Hello Vue!') |
| 67 | + }) |
| 68 | + |
| 69 | + it('changes message if data changes', () => { |
| 70 | + // mounted Vue instance is available under Cypress.vue |
| 71 | + Cypress.vue.$data.message = 'Vue rocks!' |
| 72 | + cy.contains('Vue rocks!') |
| 73 | + }) |
| 74 | +}) |
| 75 | +``` |
| 76 | + |
| 77 | +Fire up Cypress test runner and have real browser (Electron, Chrome) load |
| 78 | +Vue and mount your test code and be able to interact with the instance through |
| 79 | +the reference `Cypress.vue.$data` and via GUI. The full power of the |
| 80 | +[Cypress API](https://on.cypress.io/api) is available. |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +[cypress.io]: https://www.cypress.io/ |
| 85 | + |
21 | 86 | ### Small print |
22 | 87 |
|
23 | 88 | Author: Gleb Bahmutov <[email protected]> © 2017 |
|
0 commit comments