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