From 8887ff95ebe5fbe97297d9394dac917ff22b18bd Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 21 Jan 2021 12:36:21 +0100 Subject: [PATCH] test: client side useStore --- __tests__/store.spec.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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 -- 2.47.3