8000 fix: avoid resetting store state when registering a dynamic module by alecgibson · Pull Request #2234 · vuejs/vuex · GitHub
[go: up one dir, main page]

Skip to content

fix: avoid resetting store state when registering a dynamic module #2234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: add test case
  • Loading branch information
Azurewarth0920 authored and alecgibson committed Aug 31, 2023
commit 99d0b992efdfde19373feb01adffe118511a7580
29 changes: 28 additions & 1 deletion test/unit/modules.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { h, nextTick } from 'vue'
import { computed, h, nextTick } from 'vue'
import { mount } from 'test/helpers'
import Vuex from '@/index'

Expand Down Expand Up @@ -925,4 +925,31 @@ describe('Modules', () => {
/getters should be function but "getters\.test" in module "foo\.bar" is true/
)
})

it('module: computed getter should be reactive after module registration', () => {
const store = new Vuex.Store({
state: {
foo: 0
},
getters: {
getFoo: state => state.foo
},
mutations: {
incrementFoo: state => state.foo++
}
})

const computedFoo = computed(() => store.getters.getFoo)
store.commit('incrementFoo')
expect(computedFoo.value).toBe(1)

store.registerModule('bar', {
state: {
bar: 0
}
})

store.commit('incrementFoo')
expect(computedFoo.value).toBe(2)
})
})
0