2023-01-03 13:17:22 +00:00
|
|
|
import { installQuasar } from '@quasar/quasar-app-extension-testing-unit-vitest';
|
|
|
|
import { mount, flushPromises } from '@vue/test-utils';
|
|
|
|
import { createTestingPinia } from '@pinia/testing';
|
|
|
|
import { vi } from 'vitest';
|
|
|
|
import { i18n } from 'src/boot/i18n';
|
|
|
|
import { Notify, Dialog } from 'quasar';
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
installQuasar({
|
|
|
|
plugins: {
|
|
|
|
Notify,
|
|
|
|
Dialog,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-02-24 12:21:37 +00:00
|
|
|
const pinia = createTestingPinia({ createSpy: vi.fn, stubActions: false });
|
2023-01-03 13:17:22 +00:00
|
|
|
const mockPush = vi.fn();
|
2023-02-24 12:21:37 +00:00
|
|
|
|
2023-01-03 13:17:22 +00:00
|
|
|
vi.mock('vue-router', () => ({
|
|
|
|
useRouter: () => ({
|
|
|
|
push: mockPush,
|
|
|
|
currentRoute: { value: 'myCurrentRoute' },
|
|
|
|
}),
|
|
|
|
useRoute: () => ({
|
|
|
|
matched: [],
|
2023-02-24 12:21:37 +00:00
|
|
|
query: {},
|
|
|
|
params: {},
|
2023-01-03 13:17:22 +00:00
|
|
|
}),
|
|
|
|
}));
|
|
|
|
|
|
|
|
export function createWrapper(component, options) {
|
|
|
|
const defaultOptions = {
|
|
|
|
global: {
|
|
|
|
plugins: [i18n, pinia],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const mountOptions = Object.assign({}, defaultOptions);
|
|
|
|
|
|
|
|
if (options instanceof Object) {
|
|
|
|
Object.assign(mountOptions, options);
|
|
|
|
|
|
|
|
if (options.global) {
|
|
|
|
mountOptions.global.plugins = defaultOptions.global.plugins;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const wrapper = mount(component, mountOptions);
|
|
|
|
const vm = wrapper.vm;
|
|
|
|
|
|
|
|
return { vm, wrapper };
|
|
|
|
}
|
|
|
|
|
|
|
|
export { axios, flushPromises };
|