From 68e8ff3e7de18f5c04a6b464a92382fa0d03ae3a Mon Sep 17 00:00:00 2001 From: Jakob Scheid Date: Fri, 24 Jul 2026 12:19:17 +0200 Subject: [PATCH] feat(test-utils): add store setup functionality to mountComponent utility --- src/test-utils/mountComponent.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/test-utils/mountComponent.js b/src/test-utils/mountComponent.js index e381b3b..3f8a0a4 100644 --- a/src/test-utils/mountComponent.js +++ b/src/test-utils/mountComponent.js @@ -21,6 +21,11 @@ import { createI18n } from 'vue-i18n'; import { createMemoryHistory, createRouter } from 'vue-router'; export const mountComponent = function mountComponent (component, options = {}, i18nMessages = {}, routes = [], piniaOptions = {}) { + const { + setupStores, + ...testingPiniaOptions + } = piniaOptions; + const i18n = createI18n({ legacy: false, locale: 'en', @@ -34,16 +39,22 @@ export const mountComponent = function mountComponent (component, options = {}, routes }); + const testingPinia = createTestingPinia({ + ...testingPiniaOptions, + stubActions: false, + createSpy: vi.fn + }); + + if (setupStores) { + setupStores(); + } + return mount(component, { global: { plugins: [ i18n, router, - createTestingPinia({ - ...piniaOptions, - stubActions: false, - createSpy: vi.fn - }) + testingPinia ], }, ...options