How to mock $el
property (points to component's HTML element) when testing component? I need to have an access to mocked $el
in mounted()
hook. Solution below does not work.
const wrapper = shallowMount(Component, {
mocks: {
$el: {
//some properties
}
}
})
//Edit
Ok I found a workaround for this.
If you need access to this.$parent
or this.$el
in created/mounted hook, just write a getter method in methods and next, mock it in your wrapper and replace this.$parent
/this.$el
by mocked method.
const wrapper = mount(Component,
methods: {
getEl: () => {}
}
.