Skip to content

Commit 0989895

Browse files
committed
test: add test case
1 parent 3421086 commit 0989895

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

Diff for: test/helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import puppeteer from 'puppeteer'
44
export 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

Diff for: test/unit/modules.spec.js

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { nextTick } from 'vue'
1+
import { h, nextTick } from 'vue'
2+
import { mount } from 'test/helpers'
23
import Vuex from '@/index'
34

45
const 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

0 commit comments

Comments
 (0)