From: Eduardo San Martin Morote Date: Wed, 3 Mar 2021 16:29:16 +0000 (+0100) Subject: test: add plugins test X-Git-Tag: v0.2.0~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c4d0020f82a2d2a699078faad8283e0d510a72b7;p=thirdparty%2Fvuejs%2Fpinia.git test: add plugins test --- diff --git a/__tests__/storePlugins.spec.ts b/__tests__/storePlugins.spec.ts new file mode 100644 index 00000000..fb62ccfa --- /dev/null +++ b/__tests__/storePlugins.spec.ts @@ -0,0 +1,49 @@ +import { createPinia, defineStore, PiniaPlugin } from '../src' +import { createLocalVue, mount } from '@vue/test-utils' +import Vue from 'vue' + +declare module '../src' { + export interface PiniaCustomProperties { + n: number + // uid: App['_uid'] + hasPinia: boolean + } +} + +describe('store plugins', () => { + const useStore = defineStore({ id: 'test' }) + const localVue = createLocalVue() + localVue.use(PiniaPlugin) + + it('adds properties to stores', () => { + const pinia = createPinia() + pinia.Vue = Vue + mount({ template: '

' }, { localVue }) + + // must call use after installing the plugin + pinia.use(() => { + return { n: 20 } + }) + + const store = useStore(pinia) + + expect(store.n).toBe(20) + }) + + it('can install plugins before installing pinia', () => { + const pinia = createPinia() + pinia.Vue = Vue + + pinia.use(() => ({ n: 1 })) + pinia.use((pinia) => ({ hasPinia: !!pinia })) + + mount({ template: '

' }, { localVue }) + + pinia.use((app) => ({ hasPinia: !!app })) + + const store = useStore(pinia) + + expect(store.n).toBe(1) + expect(store.hasPinia).toBe(true) + }) +})