Skip to content

Commit d4afbec

Browse files
committed
docs: pinia plugins when testing components
1 parent ad90fd2 commit d4afbec

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/docs/cookbook/testing.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Depending on what or how you are testing, we need to take care of these three di
1515
- [Customizing behavior of actions](#customizing-behavior-of-actions)
1616
- [Specifying the createSpy function](#specifying-the-createspy-function)
1717
- [Mocking getters](#mocking-getters)
18+
- [Pinia Plugins](#pinia-plugins)
1819
- [E2E tests](#e2e-tests)
1920
- [Unit test components (Vue 2)](#unit-test-components-vue-2)
2021

@@ -203,6 +204,27 @@ counter.double = undefined
203204
counter.double // 2 (=1 x 2)
204205
```
205206

207+
### Pinia Plugins
208+
209+
If you have any pinia plugins, make sure to pass them when calling `createTestingPinia()` so they are properly applied. **Do not add them with `testingPinia.use(MyPlugin)`** like you would do with a regular pinia:
210+
211+
```js
212+
import { createTestingPinia } from '@pinia/testing'
213+
import { somePlugin } from '../src/stores/plugin'
214+
215+
// inside some test
216+
const wrapper = mount(Counter, {
217+
global: {
218+
plugins: [
219+
createTestingPinia({
220+
stubActions: false,
221+
plugins: [somePlugin],
222+
}),
223+
],
224+
},
225+
})
226+
```
227+
206228
## E2E tests
207229

208230
When it comes to pinia, you don't need to change anything for e2e tests, that's the whole point of e2e tests! You could maybe test HTTP requests, but that's way beyond the scope of this guide 😄.

0 commit comments

Comments
 (0)