@@ -45,8 +45,7 @@ const deleteCachedConstructors = component => {
45
45
const getVuePath = options =>
46
46
options . vue || options . vuePath || '../node_modules/vue/dist/vue.js'
47
47
48
- const getVuexPath = options =>
49
- options . vuex || options . vuexPath
48
+ const getVuexPath = options => options . vuex || options . vuexPath
50
49
51
50
const getPageHTML = options => {
52
51
if ( options . html ) {
@@ -91,7 +90,7 @@ const getPageHTML = options => {
91
90
<body>
92
91
<div id="app"></div>
93
92
<script src="${ vue } "></script>
94
- ${ vuex ? vuex : '' }
93
+ ${ vuex || '' }
95
94
</body>
96
95
</html>
97
96
`
@@ -136,6 +135,36 @@ const isOptions = object => Object.keys(object).every(isOptionName)
136
135
137
136
const isConstructor = object => object && object . _compiled
138
137
138
+ const hasStore = ( { store } ) => store && store . _vm
139
+
140
+ const forEachValue = ( obj , fn ) => {
141
+ Object . keys ( obj ) . forEach ( key => fn ( obj [ key ] , key ) )
142
+ }
143
+
144
+ const resetStoreVM = ( Vue , { store } ) => {
145
+ // bind store public getters
146
+ store . getters = { }
147
+ const wrappedGetters = store . _wrappedGetters
148
+ const computed = { }
149
+ forEachValue ( wrappedGetters , ( fn , key ) => {
150
+ // use computed to leverage its lazy-caching mechanism
151
+ computed [ key ] = ( ) => fn ( store )
152
+ Object . defineProperty ( store . getters , key , {
153
+ get : ( ) => store . _vm [ key ] ,
154
+ enumerable : true // for local getters
155
+ } )
156
+ } )
157
+
158
+ store . _watcherVM = new Vue ( )
159
+ store . _vm = new Vue ( {
160
+ data : {
161
+ $$state : store . _vm . _data . $$state
162
+ } ,
163
+ computed
164
+ } )
165
+ return store
166
+ }
167
+
139
168
// the double function allows mounting a component quickly
140
169
// beforeEach(mountVue(component, options))
141
170
const mountVue = ( component , optionsOrProps = { } ) => ( ) => {
@@ -159,6 +188,10 @@ const mountVue = (component, optionsOrProps = {}) => () => {
159
188
. window ( { log : false } )
160
189
. its ( 'Vue' )
161
190
. then ( Vue => {
191
+ // refresh inner Vue instance of Vuex store
192
+ if ( hasStore ( component ) ) {
193
+ component . store = resetStoreVM ( Vue , component )
194
+ }
162
195
installMixins ( Vue , options )
163
196
installPlugins ( Vue , options )
164
197
registerGlobalComponents ( Vue , options )
@@ -169,9 +202,7 @@ const mountVue = (component, optionsOrProps = {}) => () => {
169
202
Cypress . vue = new Cmp ( props ) . $mount ( '#app' )
170
203
copyStyles ( Cmp )
171
204
} else {
172
- debugger
173
- // Cypress.vue = new Vue(component).$mount('#app')
174
- const allOptions = Object . assign ( { } , component , { el : '#app' } )
205
+ const allOptions = Object . assign ( { } , component , { el : '#app' } )
175
206
Cypress . vue = new Vue ( allOptions )
176
207
copyStyles ( component )
177
208
}
0 commit comments