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
context.root.$store is undefined in tests with the Composition API #1655
Comments
Hi @saifahn , instead of getting setup() {
const vm = getCurrentInstance()
const count = computed(() => vm.$store.state.count);
function increaseCount() {
vm.$store.commit('increment')
}
return { count, increaseCount }
} |
It should be available on Actually this is probably better than using |
I fixed this in #1661 quick review someone? |
It seems like a reasonable amount of people run into this issue, so supporting it seems good.
Thanks for this @jefrydco! Managed to get the tests working in this way. |
It is possible it does exist, I could be wrong. I always use a |
Fix here #1661 Release soon. |
Version1.0.3 Hi, I'm not getting access to I've already spent a few hours trying to solve this problem and I'm not succeeding. My component: <script>
export default {
setup ( _, { root }) {
// behavior
...
watch( () => root.$route,
({ query, meta }) => {
...
}, {
immediate: true
});
}
};
</script> My test:
Return this error:
|
I think this was fixed in v1.0.5. Can you update to the latest version? |
Oh, nevermind. I didn't even compare the versions, I was so focused on the problem ...: / sorry and thanks 💯 |
Version
1.0.4
Reproduction link
https://github.com/saifahn/composition-api-context-store-undefined-vtu
Steps to reproduce
npm run test:unit
You will see the error.
What is expected?
What is actually happening?
context.root.$store
returnsundefined,
so tests involving components that usecontext.root.$store
will fail.I have seen people with similar problems using
context.root.$router
as well.Here's one:
https://forum.vuejs.org/t/vue-composition-api-vue-router-unit-test/88702
The text was updated successfully, but these errors were encountered: