From: Eduardo San Martin Morote Date: Wed, 30 Jun 2021 13:07:10 +0000 (+0200) Subject: test: multiple apps with one pinia X-Git-Tag: v2.0.0-beta.5~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f34c86f1f67ab90f36b9018718c4ae1f8158309e;p=thirdparty%2Fvuejs%2Fpinia.git test: multiple apps with one pinia --- diff --git a/__tests__/store.spec.ts b/__tests__/store.spec.ts index e38b42a1..667aa092 100644 --- a/__tests__/store.spec.ts +++ b/__tests__/store.spec.ts @@ -241,4 +241,40 @@ describe('Store', () => { expect(s1).toBeDefined() expect(s1 === s2).toBe(true) }) + + it('can share the same pinia in two completely different instances', async () => { + const useStore = defineStore({ id: 'one', state: () => ({ n: 0 }) }) + const pinia = createPinia() + + const Comp = defineComponent({ + setup() { + const store = useStore() + return { store } + }, + template: `{{ store.n }}`, + }) + + const One = mount(Comp, { + global: { + plugins: [pinia], + }, + }) + + const Two = mount(Comp, { + global: { + plugins: [pinia], + }, + }) + + const store = useStore(pinia) + + expect(One.text()).toBe('0') + expect(Two.text()).toBe('0') + + store.n++ + await nextTick() + + expect(One.text()).toBe('1') + expect(Two.text()).toBe('1') + }) })