I am fairly new to vue, and I have created a router-link with a VueRouter to navigate to a certain page.
<router-link
@click.native="onRouteClicked(index)"
/>
Now I need to mock this click.native function. I know there is a trigger function for vue components available from vue-test-utils.
But how am I to click.native from a trigger ?
my onRouteClicked looks like this
methods: {
onRouteClicked: function (index) {
this.routedIndex = index;
}
}
my test look like this
const myRouteWrapper = navBar.find('[to="/myroute"]');
myRouteWrapper.trigger('click')
expect(myComp.vm.routedIndex).equal(1);
the routedIndex is not changing at all
onRouteClickedfunction onmethodsobject? I believe that should trigger the click event.findmethod expects 3 different types of selectors. In this case, perhaps I would check if the library actually transforms the individualrouter-links into HTML anchor tag with#/myrouteas thehrefattribute, where we could instead donavBar.find('[href="#/myroute"]').