1.0.0-beta.25
https://codesandbox.io/s/8xrrjpy349
https://codesandbox.io/s/8xrrjpy349npm installnpm run test test execution will start and it will throw an error TypeError: Cannot read property 'breakpoint' of undefinedTest should run without error as given in documents https://vue-test-utils.vuejs.org/api/shallowMount.html
Returning TypeError
Only components are stubbed by shallowMount.
You're accessing $vuetify.breakpoint in the template of your component, which isn't stubbed by Vue Test Utils.
You need to add instance method, you need to use the mocks mounting option:
const wrapper = shallowMount(Titlebar, {
mocks: {
$vuetify: { breakpoint: {} }
}
})
@eddyerburgh Thanks!!
I'm working on a project with Vuetify and Typescript and no matter what I try, I always get
TypeError: Cannot read property 'smAndUp' of undefined.
Have added the vue.use(Vuetify);
Also tried adding the $vuetify object inside mocks but no luck. Anyone run into this issue?
We are getting TypeError: Cannot read property 'mobileBreakpoint' of undefined in shallowMount.
@exbarboss Could you please try to add vuetify to the mock
import Vuetify from 'vuetify';
const vuetify = new Vuetify();
const wrapper = shallowMount(VueComponentName, {
mocks: {
...
},
vuetify,
});
This works for me.
@hodovani Hi! Just tried and it is not recognizing any Vuetify components, but I think I was able to make it work:
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import Vuetify from 'vuetify';
import SideNav from '@/components/layout/SideNav.vue';
const vuetify = new Vuetify();
Vue.use(Vuetify); // <= Tried to pass here constant from above and tests are failing
describe('SideNav.vue component tests', () => {
test('is rendering correctly', () => {
const wrapper = shallowMount(SideNav, {
propsData: {
show: true,
},
vuetify,
});
expect(wrapper.element).toMatchSnapshot();
});
it('is Vue component', () => {
const wrapper = shallowMount(SideNav, {
propsData: {
show: true,
},
vuetify,
});
expect(wrapper.isVueInstance());
});
});
@hodovani Thanks!
@hodovani @exbarboss Thanks. Your suggestion works for me.
Most helpful comment
I'm working on a project with Vuetify and Typescript and no matter what I try, I always get
TypeError: Cannot read property 'smAndUp' of undefined.Have added the vue.use(Vuetify);
Also tried adding the $vuetify object inside mocks but no luck. Anyone run into this issue?