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';
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