-
Notifications
You must be signed in to change notification settings - Fork 665
setCompued does not work correctly for mapGetters #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It has been working fine for me with stuff like computed: {
something () { return this.$store.getters['module/something']
} and |
@lmiller1990 that would be great if you could investigate 😀 I copied this code over from another issue and haven't been able to test myself |
Can confirm it does not work. Will look into tomorrow. import { shallow } from 'vue-test-utils'
import mapGetters from './mapGetters'
test('it works', () => {
const wrapper = shallow(mapGetters)
wrapper.setComputed({ isTeamAdmin: true })
expect(wrapper.vm.placeholder).toEqual('Leader')
}) TypeError: Cannot read property 'isTeamAdmin' of undefined |
The below is a minimum failing example that should pass using <template>
<div>
{{ placeholder }}
</div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
name: 'mapGetters',
computed: {
...mapGetters([
'isTeamAdmin'
]),
placeholder () {
return this.isTeamAdmin ? 'Leader' : 'inboxMember'
}
}
}
</script> import Vue from 'vue'
import Vuex from 'vuex'
import { shallow } from 'vue-test-utils'
import mapGetters from './mapGetters'
Vue.use(Vuex)
test('it works', () => {
let store = new Vuex.Store({
getters: {
isTeamAdmin: () => true
}
})
const wrapper = shallow(mapGetters, {
store
})
wrapper.setComputed({ isTeamAdmin: false })
expect(wrapper.vm.placeholder).toEqual('inboxMember') // fails. Still leader.
}) Edit: If you do Edit: I think Anyway, so I think the problem is related to the fact that Was do you think we should do for this case @eddyerburgh ? Async test or even flush promises is a good workaround for now but this issue is cropping up a lot. |
@lmiller1990 just trying to understand what you meant.
Do you run the I might just have misunderstood you though, please clarify. Edit: Sorry for the confusion, I now understand there was an error thrown before that was somehow avoided with the Interestingly enough the error is not avoidable in my setup with mocha using |
I think I located the origin of the error in Vuex, This might a result of I do not understand enough about how vue-test-utils' vuex mocking works normally to go further right now. |
Hi all! Thank you, guys. |
@rayoplateado can you make your test async and use something like flush promises? If you post the code you want to test I can help you in the right direction. |
This will be fixed in beta.9 😀 |
The text was updated successfully, but these errors were encountered: