This repository was archived by the owner on Dec 12, 2020. It is now read-only.
File tree 4 files changed +57
-0
lines changed
4 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,23 @@ const extensions = {
109
109
beforeEach (mountVue ({ template, data }, { extensions }))
110
110
```
111
111
112
+ See [ Vue component docs] ( https://vuejs.org/v2/api/#Vue-component ) ,
113
+ [ message-list-spec.js] ( cypress/integration/message-list-spec.js )
114
+
115
+ * ` use ` - list of plugins
116
+
117
+ ``` js
118
+ const use = [MyPlugin]
119
+ // extend Vue with plugins
120
+ const extensions = {
121
+ use
122
+ }
123
+ beforeEach (mountVue ({}, { extensions }))
124
+ ```
125
+
126
+ See [ Vue plugin docs] ( https://vuejs.org/v2/guide/plugins.html )
127
+ and [ plugin-spec.js] ( cypress/integrstion/plugin-spec.js )
128
+
112
129
### The intro example
113
130
114
131
Take a look at the first Vue v2 example:
Original file line number Diff line number Diff line change
1
+ // https://vuejs.org/v2/guide/plugins.html
2
+ export const MyPlugin = {
3
+ install ( Vue , options ) {
4
+ // 1. add global method or property
5
+ Vue . aPluginMethod = function ( ) {
6
+ return 'foo'
7
+ }
8
+ }
9
+ }
Original file line number Diff line number Diff line change
1
+ import { MyPlugin } from '../../components/MyPlugin'
2
+ const mountVue = require ( '../..' )
3
+
4
+ /* eslint-env mocha */
5
+ describe ( 'Custom plugin MyPlugin' , ( ) => {
6
+ const use = [ MyPlugin ]
7
+
8
+ // extend Vue with plugins
9
+ const extensions = {
10
+ use
11
+ }
12
+ beforeEach ( mountVue ( { } , { extensions } ) )
13
+
14
+ it ( 'registers global method on Vue instance' , ( ) => {
15
+ cy . window ( ) . its ( 'Vue' ) . its ( 'aPluginMethod' ) . should ( 'be.a' , 'function' )
16
+ } )
17
+
18
+ it ( 'can call this global function' , ( ) => {
19
+ cy . window ( ) . its ( 'Vue' ) . invoke ( 'aPluginMethod' ) . should ( 'equal' , 'foo' )
20
+ } )
21
+ } )
Original file line number Diff line number Diff line change @@ -99,6 +99,15 @@ const registerGlobalComponents = (Vue, options) => {
99
99
}
100
100
}
101
101
102
+ const installPlugins = ( Vue , options ) => {
103
+ const plugins = Cypress . _ . get ( options , 'extensions.use' )
104
+ if ( Cypress . _ . isArray ( plugins ) ) {
105
+ plugins . forEach ( plugin => {
106
+ Vue . use ( plugin )
107
+ } )
108
+ }
109
+ }
110
+
102
111
const mountVue = ( component , options = { } ) => ( ) => {
103
112
const vueHtml = getPageHTML ( options )
104
113
const document = cy . state ( 'document' )
@@ -111,6 +120,7 @@ const mountVue = (component, options = {}) => () => {
111
120
. window ( { log : false } )
112
121
. its ( 'Vue' )
113
122
. then ( Vue => {
123
+ installPlugins ( Vue , options )
114
124
registerGlobalComponents ( Vue , options )
115
125
deleteCachedConstructors ( component )
116
126
Cypress . vue = new Vue ( component ) . $mount ( '#app' )
You can’t perform that action at this time.
0 commit comments