import {
createPinia,
defineStore,
+ disposePinia,
getActivePinia,
setActivePinia,
} from '../src'
expect(getActivePinia()).toBe(pinia)
})
- it('state reactivity outlives component life', async () => {
+ it('state reactivity outlives component life', () => {
const useStore = defineMyStore()
const inComponentWatch = vi.fn()
render: () => null,
setup() {
const store = useStore()
- watch(() => store.n, inComponentWatch)
+ watch(() => store.n, inComponentWatch, {
+ flush: 'sync',
+ })
onMounted(() => {
store.n++
})
}
let wrapper = mount(Component, options)
- await nextTick()
-
wrapper.unmount()
- await nextTick()
expect(inComponentWatch).toHaveBeenCalledTimes(1)
let store = useStore()
store.n++
- await nextTick()
expect(inComponentWatch).toHaveBeenCalledTimes(1)
wrapper = mount(Component, options)
- await nextTick()
wrapper.unmount()
- await nextTick()
expect(inComponentWatch).toHaveBeenCalledTimes(2)
store = useStore()
store.n++
- await nextTick()
expect(inComponentWatch).toHaveBeenCalledTimes(2)
})
destroy()
})
+
+ it('dispose stops store reactivity', () => {
+ const pinia = createPinia()
+ setActivePinia(pinia)
+ const inStoreWatch = vi.fn()
+
+ const useStore = defineStore('a', () => {
+ const n = ref(0)
+ watch(n, inStoreWatch, {
+ flush: 'sync',
+ })
+ return { n }
+ })
+
+ const store = useStore()
+ store.n++
+ expect(inStoreWatch).toHaveBeenCalledTimes(1)
+
+ disposePinia(pinia)
+ store.n++
+ expect(inStoreWatch).toHaveBeenCalledTimes(1)
+ })
})