Skip to content

How to test a composable that uses a vuex store inside it? #2004

Answered by cexbrayat
gabriellatavares asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @gabriellatavares

We have a dedicated guide for testing Vuex but it's more focused on testing components that use a store https://test-utils.vuejs.org/guide/advanced/vuex.html

You're indeed going to find more answers around Pinia, as it is the recommended solution over Vuex in Vue 3, but the principles should be the same

Testing a composable can be done by creating a test component that uses it, and then mounting and testing this component.
When you mount the component, you can then mock the store as explained in the guide I linked above.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@gabriellatavares
Comment options

Answer selected by gabriellatavares
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants