feat(test-utils): add store setup functionality to mountComponent utility

This commit is contained in:
2026-07-24 12:19:17 +02:00
parent 9ce4cec0bf
commit f2d228c24e
+16 -5
View File
@@ -21,6 +21,11 @@ import { createI18n } from 'vue-i18n';
import { createMemoryHistory, createRouter } from 'vue-router'; import { createMemoryHistory, createRouter } from 'vue-router';
export const mountComponent = function mountComponent (component, options = {}, i18nMessages = {}, routes = [], piniaOptions = {}) { export const mountComponent = function mountComponent (component, options = {}, i18nMessages = {}, routes = [], piniaOptions = {}) {
const {
setupStores,
...testingPiniaOptions
} = piniaOptions;
const i18n = createI18n({ const i18n = createI18n({
legacy: false, legacy: false,
locale: 'en', locale: 'en',
@@ -34,16 +39,22 @@ export const mountComponent = function mountComponent (component, options = {},
routes routes
}); });
const testingPinia = createTestingPinia({
...testingPiniaOptions,
stubActions: false,
createSpy: vi.fn
});
if (setupStores) {
setupStores();
}
return mount(component, { return mount(component, {
global: { global: {
plugins: [ plugins: [
i18n, i18n,
router, router,
createTestingPinia({ testingPinia
...piniaOptions,
stubActions: false,
createSpy: vi.fn
})
], ],
}, },
...options ...options