Skip to content

Instantly share code, notes, and snippets.

@LeandrodeLimaC
Last active December 26, 2022 19:44
Show Gist options
  • Save LeandrodeLimaC/1f27613e65bc0d42a6bd781e0e11193e to your computer and use it in GitHub Desktop.
Save LeandrodeLimaC/1f27613e65bc0d42a6bd781e0e11193e to your computer and use it in GitHub Desktop.
Wrapper factory that receives if it's a ShallowMount or not. It's helpful to easy your (and mine) life when creating vue unit tests (You can extend this to import and use Router, Vuex, etc)
import Vue from 'vue';
import Vuetify from 'vuetify';
import { createLocalVue, shallowMount, mount } from '@vue/test-utils';
// I'do prefer to create a mocks file for those global fellas
// import mocks from './mocks';
Vue.use(Vuetify);
export default (component, options = {}, shallow = true) => {
const { localVue, vuetify } = create();
let params = [
component, {
localVue,
vuetify,
// ...mocks,
...options,
}
]
if(!shallow) return mount(...params);
return shallowMount(...params);
};
// If you're using vue-test-utils 2.0, you can do the below masterpiece
// more info -> https://vue-test-utils.vuejs.org/v2/guide/stubs-shallow-mount.html#stubbing-all-children-components
// export default (component, options = {}, useShallow = true) => {
// const { localVue, vuetify } = create();
// return mount(component, {
// localVue,
// shallow: useShallow,
// vuetify,
// ...mocks,
// ...options,
// });
// };
const create = () => {
const localVue = createLocalVue();
let vuetify = new Vuetify();
return { vuetify, localVue };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment