© 2026 Hedgehog Software, LLC
export const useTestStore = defineStore('test-store', () => { function test1 () { console.log('before') test2() console.log('after') } function test2 () { console.log('test 2 called') } return { test1, test2 } })
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest' import { setActivePinia, createPinia } from 'pinia' describe('useTestStore', () => { beforeEach(() => { const pinia = createPinia() setActivePinia(pinia) }) it('should call test2', () => { const testStore = useTestStore() const test2Spy = vi.spyOn(testStore, 'test2') testStore.test1() expect(test2Spy).toHaveBeenCalledOnce() }) })
AssertionError: expected "spy" to be called once, but got 0 times