]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
test: multiple apps with one pinia
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 30 Jun 2021 13:07:10 +0000 (15:07 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 30 Jun 2021 13:07:10 +0000 (15:07 +0200)
__tests__/store.spec.ts

index e38b42a1c2c771d01e62426ddb56e657404abfad..667aa0921cba0c80d107fd1b67dd350e33fdfd4e 100644 (file)
@@ -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')
+  })
 })