From f34c86f1f67ab90f36b9018718c4ae1f8158309e Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 30 Jun 2021 15:07:10 +0200 Subject: [PATCH] test: multiple apps with one pinia --- __tests__/store.spec.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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') + }) }) -- 2.47.2