generated from Seekra/repository-template
feat(test-utils): add store setup functionality to mountComponent utility
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user