File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Expand file tree Collapse file tree 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'
44export function mount ( store , component ) {
55 const el = createElement ( )
66
7- component . render = ( ) => { }
7+ component . render = component . render ? component . render : ( ) => { }
88
99 const app = createApp ( component )
1010
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'
23import Vuex from '@/index'
34
45const TEST = 'TEST'
@@ -124,6 +125,49 @@ describe('Modules', () => {
124125 store . commit ( 'a/foo' )
125126 expect ( mutationSpy ) . toHaveBeenCalled ( )
126127 } )
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+ } )
127171 } )
128172
129173 // #524
You can’t perform that action at this time.
0 commit comments