LoginSignup
0
1

More than 1 year has passed since last update.

Piniaを使ったコンポーネントのテスト

Last updated at Posted at 2022-07-14

環境

Vue3
TypeScript

導入

npm install --save-dev @pinia/testing

記述

import { setActivePinia, createPinia } from 'pinia'
import { useHogeStore } from 'src/stores/hogeStore'
import { createTestingPinia } from '@pinia/testing'

discribe('hogeComponent', () => {
  beforeEach(() => {
    setActivePinia(createPinia())
  }

 it('hoge test', () => {
    const hogeStoreInit = {hoge: 'hoge', fuga: 'fuga'}
    const wrapper = mount(HogeComponent, {
      global: {
        plugins: [
          createTestingPinia({initialState: hogeStoreInit})
        ]
      }
    }
    const hogeStore = useHogeStore()

    expect(hogeStore.hoge).toBe('hoge')
    expect(hogeStore.fuga).toBe('fuga')
  }
}

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1