salix-front/test/cypress/support/component.js

52 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-05-29 09:11:48 +00:00
import { createTestingPinia } from '@pinia/testing';
import { mount } from 'cypress/vue';
import { i18n } from 'src/boot/i18n';
const pinia = createTestingPinia({ createSpy: () => {}, stubActions: false });
// // Run this code before each *test*.
// beforeEach(() => {
// // New Pinia
// pinia = createPinia();
// console.log(pinia);
// // Set current Pinia instance
// setActivePinia(pinia);
// });
function createWrapper(component, options) {
const defaultOptions = {
global: {
plugins: [i18n, pinia],
},
mocks: {
t: (tKey) => tKey,
$t: (tKey) => tKey,
},
};
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 wrapper;
}
// declare global {
// namespace Cypress {
// interface Chainable {
// createWrapper: typeof createWrapper;
// }
// }
// }
Cypress.Commands.add('createWrapper', createWrapper);
// Cypress.Commands.add('mount', mount);