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
Computed property does not reevaluate after setMethods is used on a method that is called inside a computed property if the property is rendered in the template.
Below there are two computed properties which depend on the can() method.
In the test, replacing the can() method with a true value with setMethods will still yield false on usedInTemplate
it('should reevaluate usedInTemplate when the Can method is changed',()=>{wrapper.setMethods({can: ()=>{returntrue}})expect(wrapper.vm.usedInTemplate).toBeTruthy()//fails})
In the test, replacing the can() method with a true value with setMethods will yield true on notUsedInTemplate
it('should reevaluate notUsedInTemplate when the Can method is changed',()=>{wrapper.setMethods({can: ()=>{returntrue}})expect(wrapper.vm.notUsedInTemplate).toBeTruthy()//passes})
What is expected?
Computed property should reevaluate
What is actually happening?
Computed property is not reevaluating
The text was updated successfully, but these errors were encountered:
I have a global mixin can as part of my authorization where I check if the User has the given permission and use that to conditionally render parts of my application.
Glad you found a work around. The way I normally would test these (I have the exact same thing in my app, $store.auth.roles or something like that) is to just provide a new Vuex store for each test.
Glad my book was of use! I am always looking to include more useful content, you can open an issue there if you have an idea.
Another way you can do this is by using the computed mounting option, if you moved can and cannot to computed properties (they don't appear to have any arguments, so that should work).
Version
1.0.0-beta.31
Reproduction link
https://github.com/enriqg9/vue-test-utils-setmethod-replace-computed
Steps to reproduce
Computed property does not reevaluate after
setMethods
is used on a method that is called inside a computed property if the property is rendered in the template.Below there are two computed properties which depend on the
can()
method.The
usedInTemplate
property is rendered inside the template and the value is cached to false.In the test, replacing the
can()
method with atrue
value withsetMethods
will still yield false onusedInTemplate
In the test, replacing the
can()
method with atrue
value withsetMethods
will yield true onnotUsedInTemplate
What is expected?
Computed property should reevaluate
What is actually happening?
Computed property is not reevaluating
The text was updated successfully, but these errors were encountered: