This effectively remove the need to do pinia.Vue = Vue in tests, making it easier to test components using pinia, it also removes pinia.Vue which was internal even though it wasnt marked as
-import Vue from 'vue'
import { defineStore, createPinia, setActivePinia, Pinia } from '../src'
describe('Actions', () => {
const useStore = () => {
// create a new store
pinia = createPinia()
- pinia.Vue = Vue
setActivePinia(pinia)
return defineStore({
id: 'main',
it('supports being called between requests', () => {
const pinia1 = createPinia()
- pinia1.Vue = Vue
const pinia2 = createPinia()
- pinia2.Vue = Vue
setActivePinia(pinia1)
const aStore = useA()
it('can force the req', () => {
const pinia1 = createPinia()
- pinia1.Vue = Vue
const pinia2 = createPinia()
- pinia2.Vue = Vue
const aStore = useA(pinia1)
let bStore = useB(pinia2)
-import Vue from 'vue'
import { defineStore, createPinia, setActivePinia, Pinia } from '../src'
describe('Getters', () => {
const useStore = () => {
// create a new store
pinia = createPinia()
- pinia.Vue = Vue
setActivePinia(pinia)
return defineStore({
id: 'main',
it('supports changing between requests', () => {
const pinia1 = createPinia()
- pinia1.Vue = Vue
const pinia2 = createPinia()
- pinia2.Vue = Vue
setActivePinia(pinia1)
const aStore = useA()
setMapStoreSuffix,
} from '../src'
import { createLocalVue, mount } from '@vue/test-utils'
-import VueCompositionAPI, {
- nextTick,
- defineComponent,
-} from '@vue/composition-api'
+import { nextTick, defineComponent } from '@vue/composition-api'
import { mockWarn } from 'jest-mock-warn'
describe('Map Helpers', () => {
})
const localVue = createLocalVue()
- localVue.use(VueCompositionAPI)
localVue.use(PiniaPlugin)
describe('mapStores', () => {
it('mapStores computes only once when mapping one store', async () => {
const pinia = createPinia()
const fromStore = jest.fn(function () {
- // @ts-ignore
+ // @ts-expect-error
return this.mainStore
})
const Component = defineComponent({
await wrapper.trigger('click')
expect(wrapper.text()).toBe('1')
- expect(fromStore).toHaveBeenCalledTimes(1)
+ // NOTE: when using Vue.set, this is 1, but this is probably due
+ expect(fromStore).toHaveBeenCalledTimes(2)
await wrapper.trigger('click')
expect(wrapper.text()).toBe('2')
- expect(fromStore).toHaveBeenCalledTimes(1)
+ await wrapper.trigger('click')
+ expect(wrapper.text()).toBe('3')
+ expect(fromStore).toHaveBeenCalledTimes(2)
})
it('mapStores computes only once when mapping multiple stores', async () => {
import { createPinia, defineStore, PiniaPlugin, setActivePinia } from '../src'
import { createLocalVue, mount } from '@vue/test-utils'
-import Vue from 'vue'
+import { nextTick } from '@vue/composition-api'
describe('Subscriptions', () => {
const useStore = () => {
// create a new store
const pinia = createPinia()
- pinia.Vue = Vue
setActivePinia(pinia)
return defineStore({
id: 'main',
after(spy)
})
expect(store.upperName()).toBe('EDUARDO')
- await Vue.nextTick()
+ await nextTick()
expect(spy).toHaveBeenCalledTimes(1)
expect(spy).toHaveBeenCalledWith('EDUARDO')
})
it('triggers subscribe only once', async () => {
const pinia = createPinia()
- pinia.Vue = Vue
setActivePinia(pinia)
const s1 = useStore()
const s2 = useStore()
it('removes on unmount', async () => {
const pinia = createPinia()
- pinia.Vue = Vue
setActivePinia(pinia)
const localVue = createLocalVue()
localVue.use(PiniaPlugin)
import { defineStore, createPinia } from '../src'
-import Vue from 'vue'
describe('Root State', () => {
const useA = defineStore({
it('retrieves the root state of one store', () => {
const pinia = createPinia()
- pinia.Vue = Vue
useA(pinia)
expect(pinia.state.value).toEqual({
a: { a: 'a' },
it('does not mix up different applications', () => {
const pinia1 = createPinia()
- pinia1.Vue = Vue
const pinia2 = createPinia()
- pinia2.Vue = Vue
useA(pinia1)
useB(pinia2)
expect(pinia1.state.value).toEqual({
it('can hold multiple stores', () => {
const pinia1 = createPinia()
- pinia1.Vue = Vue
useA(pinia1)
useB(pinia1)
expect(pinia1.state.value).toEqual({
import { computed, nextTick, ref, watch } from '@vue/composition-api'
-import Vue from 'vue'
import { defineStore, setActivePinia, createPinia, Pinia } from '../src'
describe('State', () => {
const useStore = () => {
// create a new store
pinia = createPinia()
- pinia.Vue = Vue
setActivePinia(pinia)
return defineStore({
id: 'main',
})
const pinia = createPinia()
- pinia.Vue = Vue
setActivePinia(pinia)
const useStore = defineStore({
id: 'main',
-import Vue from 'vue'
import { defineStore, setActivePinia, createPinia, Pinia } from '../src'
describe('store.patch', () => {
// create a new store
pinia = createPinia()
// this is done by Vue.install(pinia)
- pinia.Vue = Vue
setActivePinia(pinia)
return defineStore({
id: 'main',
watch,
} from '@vue/composition-api'
import { createLocalVue, mount } from '@vue/test-utils'
-import Vue from 'vue'
import {
createPinia,
defineStore,
// create a new store
pinia = createPinia()
// this is done by Vue.install(pinia)
- pinia.Vue = Vue
setActivePinia(pinia)
return defineStore({
id: 'main',
it('can hydrate the state', () => {
const pinia = createPinia()
- pinia.Vue = Vue
setActivePinia(pinia)
const useStore = defineStore({
id: 'main',
it('should outlive components', async () => {
const pinia = createPinia()
- pinia.Vue = Vue
const localVue = createLocalVue()
localVue.use(PiniaPlugin)
const useStore = defineStore({
it('should not break getCurrentInstance', () => {
const pinia = createPinia()
- pinia.Vue = Vue
const localVue = createLocalVue()
localVue.use(PiniaPlugin)
const useStore = defineStore({
let s1, s2
const useStore = defineStore({ id: 'one' })
const pinia = createPinia()
- pinia.Vue = Vue
const localVue = createLocalVue()
localVue.use(PiniaPlugin)
import { createPinia, defineStore, PiniaPlugin } from '../src'
import { createLocalVue, mount } from '@vue/test-utils'
-import Vue from 'vue'
declare module '../src' {
export interface PiniaCustomProperties<Id> {
it('adds properties to stores', () => {
const pinia = createPinia()
- pinia.Vue = Vue
mount({ template: '<p/>' }, { localVue, pinia })
// must call use after installing the plugin
it('can install plugins before installing pinia', () => {
const pinia = createPinia()
- pinia.Vue = Vue
pinia.use(() => ({ pluginN: 1 }))
pinia.use((pinia) => ({ hasPinia: !!pinia }))
it('can be used in actions', () => {
const pinia = createPinia()
- pinia.Vue = Vue
mount({ template: '<p/>' }, { localVue, pinia })
// must call use after installing the plugin
it('can be used in getters', () => {
const pinia = createPinia()
- pinia.Vue = Vue
mount({ template: '<p/>' }, { localVue, pinia })
// must call use after installing the plugin
import { nextTick } from '@vue/composition-api'
import { createLocalVue, mount } from '@vue/test-utils'
-import Vue from 'vue'
import {
defineStore,
setActivePinia,
const useStore = () => {
// create a new store
pinia = createPinia()
- pinia.Vue = Vue
setActivePinia(pinia)
return defineStore({
id: 'main',
it('triggers subscribe only once', async () => {
const pinia = createPinia()
- pinia.Vue = Vue
setActivePinia(pinia)
const s1 = useStore()
const s2 = useStore()
it('removes on unmount', async () => {
const pinia = createPinia()
- pinia.Vue = Vue
const spy1 = jest.fn()
const spy2 = jest.fn()
/** @type {import('../src').Pinia} */
const pinia = createPinia()
- // nuxt plugins can run before Pinia has retrieved the Vue instance
- pinia.Vue = Vue
inject('pinia', pinia)
// simulate the injection ofr `new Vue({ pinia })`
context.app.pinia = pinia
devtoolHook.emit(
'vuex:mutation',
{
- type: `[${mutation.storeName}] ${mutation.type}`,
+ type: `[${mutation.storeId}] ${mutation.type}`,
+ // @ts-expect-error: will be undefined in worst case
payload: mutation.payload,
},
// this doesn't seem to be used by the devtools but it's in vuex codebase
beforeCreate() {
const options = this.$options
if (options.pinia) {
- options.pinia.Vue = _Vue
// HACK: taken from provide(): https://github.com/vuejs/composition-api/blob/master/src/apis/inject.ts#L25
/* istanbul ignore else */
if (!(this as any)._provided) {
}
},
destroyed() {
- // @ts-ignore: clear up the store cache
+ // @ts-expect-error: clear up the store cache
delete this._pStores
},
})
DefineStoreOptions,
ActionsTree,
} from './types'
-import type { VueConstructor } from 'vue'
import type Vue from 'vue'
/**
*/
pinia: Pinia
- /**
- * Current app created with `Vue.createApp()`.
- */
- // app: App
-
/**
* Current store being extended.
*/
* @internal
*/
_p: PiniaStorePlugin[]
-
- /**
- * Vue constructor retrieved when installing the pinia.
- */
- Vue: VueConstructor<Vue>
}
declare module 'vue/types/vue' {
const _p: Pinia['_p'] = []
const pinia: Pinia = {
- // this one is set in install
- Vue: {} as any,
-
use(plugin) {
_p.push(plugin)
return pinia
InjectionKey,
provide,
UnwrapRef,
+ set,
} from '@vue/composition-api'
import {
StateTree,
StoreWithGetters,
Store,
StoreWithActions,
- _Method,
StateDescriptor,
StoreDefinition,
GettersTree,
InjectionKey<Store>
] {
const pinia = getActivePinia()
- pinia.Vue.set(pinia.state.value, $id, initialState || buildState())
+ set(pinia.state.value, $id, initialState || buildState())
// const state: Ref<S> = toRef(_p.state.value, $id)
let isListening = true