You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ npm run test:unit
...
MOCHA Testing...
router.push
beforeMount App
[!] beforeMount Parent
beforeMount Nested
beforeRouteUpdate Parent
beforeRouteUpdate Nested
[!] beforeMount Parent
beforeMount Nested
1) calls beforeMount only once
1 failing
1) router.push
calls beforeMount only once:
AssertionError: expected 2 to equal 1
expected - actual
-2
1
at Context.it (dist/js/webpack:/tests/unit/router.spec.js:83:1)
at process._tickCallback (internal/process/next_tick.js:68:7)
The issue was introduced by this commit, changes with _Ctor = {} assignments.
If these assignments are commented out, the tests starts working.
It also works if we don't use Vue.extend to define the component:
...
{
path: "/user/:id",
// It works, if we don't use Vue.extend.
component: {
// component: Vue.extend({
// Component with children, nested router-view.
render: function (h) {
return h("router-view");
},
...
And Vue.extend is needed for typescript-based setup, to have the typing working for components (also, I am actually using vue class-based components which is the best setup I found to make use of typescript checks for Vue components).
One more note: I was not able to reproduce the issue with vue test utils codebase - the same test passes with beta 30 codebase (although, I am not sure if I am doing something wrong with the setup or the this is something in the tests setup affecting the behavior).
There is a modified version that runs the same test twice and it passes for the first time and then fails the second time, but I am not sure if this is the exact same issue as described above, but maybe it will be useful too.
Test project setup
Test project is generated with vue cli (default settings unit-mocha, vue router and vue test utils):
Awesome! I didn't expect it to be resolved that soon and yes, the changes reverted in #1479 are the exact same bits that I also found to be problematic.
Version
1.0.0-beta.30
Reproduction link
https://github.com/serebrov/vue-test-utils-router-push-issue
Steps to reproduce
The issue: components
beforeMount
hook is called for the second time when route is updated to the same component/
/user/1/post1
(points to the component with children)beforeMount
is called/user/1/post2
(points to the same component)beforeMount
is called againWhat is expected?
Expected:
beforeMount
is called only once (it works this way in the real vue app and in 1.0.0-beta.29)What is actually happening?
Problem: the
beforeMount
is called againVue.extend
to define the component (or with class-based components)_Ctor = {}
assignments.Details
The demo setup: https://github.com/serebrov/vue-test-utils-router-push-issue
The failing test passes successfully in beta 29, but fails in beta 30:
Now, install and run with beta 30:
The issue was introduced by this commit, changes with
_Ctor = {}
assignments.If these assignments are commented out, the tests starts working.
It also works if we don't use
Vue.extend
to define the component:And
Vue.extend
is needed for typescript-based setup, to have the typing working for components (also, I am actually using vue class-based components which is the best setup I found to make use of typescript checks for Vue components).One more note: I was not able to reproduce the issue with vue test utils codebase - the same test passes with beta 30 codebase (although, I am not sure if I am doing something wrong with the setup or the this is something in the tests setup affecting the behavior).
There is a modified version that runs the same test twice and it passes for the first time and then fails the second time, but I am not sure if this is the exact same issue as described above, but maybe it will be useful too.
Test project setup
Test project is generated with vue cli (default settings unit-mocha, vue router and vue test utils):
The text was updated successfully, but these errors were encountered: