]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: pinia plugins when testing components
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 25 Apr 2022 13:18:08 +0000 (15:18 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 25 Apr 2022 13:18:08 +0000 (15:18 +0200)
packages/docs/cookbook/testing.md

index e37c32102e22ac11fa91cff84fc7af80143bf007..483d3bb2f9912eb8008c8eca0e6738c780f74238 100644 (file)
@@ -15,6 +15,7 @@ Depending on what or how you are testing, we need to take care of these three di
     - [Customizing behavior of actions](#customizing-behavior-of-actions)
     - [Specifying the createSpy function](#specifying-the-createspy-function)
     - [Mocking getters](#mocking-getters)
+    - [Pinia Plugins](#pinia-plugins)
   - [E2E tests](#e2e-tests)
   - [Unit test components (Vue 2)](#unit-test-components-vue-2)
 
@@ -203,6 +204,27 @@ counter.double = undefined
 counter.double // 2 (=1 x 2)
 ```
 
+### Pinia Plugins
+
+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:
+
+```js
+import { createTestingPinia } from '@pinia/testing'
+import { somePlugin } from '../src/stores/plugin'
+
+// inside some test
+const wrapper = mount(Counter, {
+  global: {
+    plugins: [
+      createTestingPinia({
+        stubActions: false,
+        plugins: [somePlugin],
+      }),
+    ],
+  },
+})
+```
+
 ## E2E tests
 
 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 ðŸ˜„.