Skip to content

Instantly share code, notes, and snippets.

@NicolasDurant
Last active July 12, 2020 16:41
Show Gist options
  • Save NicolasDurant/268541909853db1a3ac101106686a6a4 to your computer and use it in GitHub Desktop.
Save NicolasDurant/268541909853db1a3ac101106686a6a4 to your computer and use it in GitHub Desktop.
[Nuxt - Jest Extracted Mountfunction] Helper file that I created to follow the DRY principle. Mocks most used variables/methods so the test files aren't so stacked. You can add mock-data for vuetify/components in this file, but keep in mind this will be added to all tests importing this helper. Jest could become slower if you stub stuff that is …
import { shallowMount, createLocalVue } from '@vue/test-utils'
import Vuetify from 'vuetify'
// You can add mock-data for vuetify/components in this file, but keep in mind this will be added to all tests importing this helper
// -> jest could become slower if you stub stuff that is not useful for each test
const localVue = createLocalVue();
// if you need to stub more vuetify variables or methods add them here
const vuetify = new Vuetify({
mocks: {
$vuetify: {
breakpoint: {
mdAndUp: (val) => val,
},
},
}
});
// you can add common mocks here as well
export const mountFunction = (component, options) => {
return shallowMount(component, {
localVue,
vuetify,
mocks: {
$t: () => {},
inspect: () => {},
},
...options,
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment