Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
kiaking committed Nov 22, 2020
1 parent 3421086 commit 0989895
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/helpers.js
Expand Up @@ -4,7 +4,7 @@ import puppeteer from 'puppeteer'
export function mount (store, component) {
const el = createElement()

component.render = () => {}
component.render = component.render ? component.render : () => {}

const app = createApp(component)

Expand Down
46 changes: 45 additions & 1 deletion test/unit/modules.spec.js
@@ -1,4 +1,5 @@
import { nextTick } from 'vue'
import { h, nextTick } from 'vue'
import { mount } from 'test/helpers'
import Vuex from '@/index'

const TEST = 'TEST'
Expand Down Expand Up @@ -124,6 +125,49 @@ describe('Modules', () => {
store.commit('a/foo')
expect(mutationSpy).toHaveBeenCalled()
})

it.only('should keep getters when component gets destroyed', async () => {
const store = new Vuex.Store()

const moduleA = {
namespaced: true,
state: () => ({ value: 1 }),
getters: {
getState: (state) => state.value
},
mutations: {
increment: (state) => { state.value++ }
}
}

const CompA = {
template: `<div />`,
created () {
this.$store.registerModule('moduleA', moduleA)
}
}

const CompB = {
template: `<div />`
}

const vm = mount(store, {
components: { CompA, CompB },
data: () => ({ show: 'a' }),
render () {
return this.show === 'a' ? h(CompA) : h(CompB)
}
})

expect(store.getters['moduleA/getState']).toBe(1)

vm.show = 'b'
await nextTick()

store.commit('moduleA/increment')
console.log(store.state.moduleA.value)
expect(store.getters['moduleA/getState']).toBe(2)
})
})

// #524
Expand Down

0 comments on commit 0989895

Please sign in to comment.