]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
test: client side useStore
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 21 Jan 2021 11:36:21 +0000 (12:36 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 21 Jan 2021 11:36:21 +0000 (12:36 +0100)
__tests__/store.spec.ts

index 01702135e93b36744c1d909553df4cd5a8ef9971..3597f5a0d8ae555102c9b58f2702da80eff67d62 100644 (file)
@@ -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: `<div>{{ store. n }}</div>`,
+      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