All skills
skilld-dev avatar

/pinia-skilld

@b9c39cb

Use when writing, debugging, or refactoring code that imports "pinia", the Vue 3 store library. Covers pinia 4.x: option and setup stores, state, getters, actions, subscriptions, plugins, SSR hydration, testing, Options API map helpers, and v4 nostics diagnostics. Provides version-correct API usage and migration notes from v2 and v3.

Use this Skill: https://skilld.dev/gh/skilld-dev/vue-ecosystem-skills/pinia-skilld

This session only. Nothing lands on disk.

referencestesting.md

≈581 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Testing

Unit testing a store

Create a fresh pinia per test and make it active:

import { setActivePinia, createPinia } from 'pinia'
import { useCounterStore } from '../src/stores/counter'

beforeEach(() => {
  setActivePinia(createPinia())
})

it('increments', () => {
  const counter = useCounterStore()
  counter.increment()
  expect(counter.n).toBe(1)
})

setActivePinia sets the instance that bare useStore() calls resolve to [dist/pinia.js:70].

Plugins only run after the pinia is installed in an app. Use a fake app:

const app = createApp({})
beforeEach(() => {
  const pinia = createPinia().use(somePlugin)
  app.use(pinia)
  setActivePinia(pinia)
})

Dispose instances between complex tests with disposePinia(pinia) [dist/pinia.d.ts:589-595].

Component tests: @pinia/testing 2.x

createTestingPinia() stubs every action as a spy by default:

import { mount } from '@vue/test-utils'
import { createTestingPinia } from '@pinia/testing'
import { useSomeStore } from '@/stores/myStore'

const wrapper = mount(Component, {
  global: { plugins: [createTestingPinia()] },
})

const store = useSomeStore()
store.someAction()
expect(store.someAction).toHaveBeenCalledTimes(1)

Options:

  • stubActions: false runs the real implementations, still spied.
  • stubActions: ['increment', 'reset'] stubs only named actions; an empty array stubs none; a function (name, store) => boolean decides per action.
  • initialState: { counter: { n: 20 } } patches state at store creation.
  • createSpy: vi.fn when vitest globals: true is off, or for other frameworks.

Pass store plugins through the plugins option. Do not call testingPinia.use(); plugins added that way are not applied.

Getters stay live computed in tests. store.double = 3 forces a value; set it back to undefined to restore computation.

Install: npm i -D @pinia/testing. Use 2.x with pinia 4 (https://github.com/vuejs/pinia/releases).

How the testing bypass works

A testing pinia sets _testing on the instance. In NODE_ENV === "test", useStore() ignores its pinia argument and uses the active testing pinia instead [dist/pinia.js:534-535,1307]. This is why setActivePinia(createTestingPinia()) redirects bare useStore() calls in tests.

https://pinia.vuejs.org/cookbook/testing.html

Source: SKILL.md on GitHub

No alerts8d3 checks · Risk SAFE
  • Gen Agent Trust Hub8d

    This skill is a comprehensive documentation and reference set for the Pinia state management library. It consists entirely of markdown files including official guides, changelogs, and mirrored GitHub issues/discussions. No malicious code, exfiltration patterns, or harmful instructions were detected.

  • Socket8d

    No alerts

  • Snyk8d

    Risk: LOW · No issues

Signed by skilld at b9c39cb. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated last week

README badge

README badge for skilld-dev/vue-ecosystem-skills/pinia-skilld