pinia icon indicating copy to clipboard operation
pinia copied to clipboard

Allow stubbing specific actions only

Open posva opened this issue 9 months ago โ€ข 0 comments

What problem is this solving

createTestingPinia() can stub or spy all actions but in some cases, it's useful to stub only a few ones

Proposed solution

  • Adapt the option of stubActions for { include, exclude }

  • Document that you can mock a specific action:

    const counter = useStore()
    vi.spyOn(counter, 'increment').mockImplementation(() => {})
    // or if using testing pinia
    counter.increment.mockImplementation()
    
    • see https://pinia.vuejs.org/cookbook/testing.html#Mocking-the-returned-value-of-an-action to have the second version wor

Describe alternatives you've considered

No response

posva avatar Apr 11 '25 07:04 posva