Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to test next function in beforeRouteEnter()#2509

Unanswered
steven-twerdochlib asked this question inQ&A
Discussion options

Hi,
I have the following code:

beforeRouteEnter(to, from, next) {    next((vm: any) => {      if (to.name !== from.name) {        vm.$store.commit('randomFunction');      }    });  },

How would I create a test that checks $store.commit was called with 'randomFunction'?
I've read you can test before RouteEnter with thisMyComponent.beforeRouteEnter.call(wrapper.vm, undefined, undefined, next) but the issue with this is I have to define the next function in my test class which would mean it won't detect changes in the .vue class and correctly signal failures if the logic has changed.

You must be logged in to vote

Replies: 1 comment

Comment options

Hi@steven-twerdochlib
You should check outhttps://github.com/posva/vue-router-mock and trigger a navigation to the component you want to test, so that beforeRouteEnter run.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@steven-twerdochlib@cexbrayat

[8]ページ先頭

©2009-2025 Movatter.jp