File tree 2 files changed +46
-2
lines changed
2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import puppeteer from 'puppeteer'
4
4
export function mount ( store , component ) {
5
5
const el = createElement ( )
6
6
7
- component . render = ( ) => { }
7
+ component . render = component . render ? component . render : ( ) => { }
8
8
9
9
const app = createApp ( component )
10
10
Original file line number Diff line number Diff line change 1
- import { nextTick } from 'vue'
1
+ import { h , nextTick } from 'vue'
2
+ import { mount } from 'test/helpers'
2
3
import Vuex from '@/index'
3
4
4
5
const TEST = 'TEST'
@@ -124,6 +125,49 @@ describe('Modules', () => {
124
125
store . commit ( 'a/foo' )
125
126
expect ( mutationSpy ) . toHaveBeenCalled ( )
126
127
} )
128
+
129
+ it . only ( 'should keep getters when component gets destroyed' , async ( ) => {
130
+ const store = new Vuex . Store ( )
131
+
132
+ const moduleA = {
133
+ namespaced : true ,
134
+ state : ( ) => ( { value : 1 } ) ,
135
+ getters : {
136
+ getState : ( state ) => state . value
137
+ } ,
138
+ mutations : {
139
+ increment : ( state ) => { state . value ++ }
140
+ }
141
+ }
142
+
143
+ const CompA = {
144
+ template : `<div />` ,
145
+ created ( ) {
146
+ this . $store . registerModule ( 'moduleA' , moduleA )
147
+ }
148
+ }
149
+
150
+ const CompB = {
151
+ template : `<div />`
152
+ }
153
+
154
+ const vm = mount ( store , {
155
+ components : { CompA, CompB } ,
156
+ data : ( ) => ( { show : 'a' } ) ,
157
+ render ( ) {
158
+ return this . show === 'a' ? h ( CompA ) : h ( CompB )
159
+ }
160
+ } )
161
+
162
+ expect ( store . getters [ 'moduleA/getState' ] ) . toBe ( 1 )
163
+
164
+ vm . show = 'b'
165
+ await nextTick ( )
166
+
167
+ store . commit ( 'moduleA/increment' )
168
+ console . log ( store . state . moduleA . value )
169
+ expect ( store . getters [ 'moduleA/getState' ] ) . toBe ( 2 )
170
+ } )
127
171
} )
128
172
129
173
// #524
You can’t perform that action at this time.
0 commit comments