From: Eduardo San Martin Morote Date: Thu, 21 Jan 2021 11:36:21 +0000 (+0100) Subject: test: client side useStore X-Git-Tag: v2.0.0-alpha.8~116 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8887ff95ebe5fbe97297d9394dac917ff22b18bd;p=thirdparty%2Fvuejs%2Fpinia.git test: client side useStore --- diff --git a/__tests__/store.spec.ts b/__tests__/store.spec.ts index 01702135..3597f5a0 100644 --- a/__tests__/store.spec.ts +++ b/__tests__/store.spec.ts @@ -31,6 +31,30 @@ describe('Store', () => { }) }) + it('works without setting the active pinia', async () => { + const pinia = createPinia() + const useStore = defineStore({ + id: 'main', + state: () => ({ n: 0 }), + }) + const TestComponent = { + template: `
{{ store. n }}
`, + setup() { + const store = useStore() + return { store } + }, + } + const w1 = mount(TestComponent, { global: { plugins: [pinia] } }) + const w2 = mount(TestComponent, { global: { plugins: [pinia] } }) + expect(w1.text()).toBe('0') + expect(w2.text()).toBe('0') + + w1.vm.store.n++ + await w1.vm.$nextTick() + expect(w1.text()).toBe('1') + expect(w2.text()).toBe('1') + }) + it('can be reset', () => { const store = useStore() store.$state.a = false