添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
很酷的生菜  ·  s3 表函数 | ClickHouse Docs·  2 周前    · 
眼睛小的生姜  ·  Use ...·  2 周前    · 
怕考试的炒粉  ·  [Calling Third-party ...·  2 周前    · 
豪情万千的米饭  ·  Testing MVI View ...·  2 周前    · 
乖乖的斑马  ·  How do I access ...·  1 周前    · 
玉树临风的弓箭  ·  Europe PMC·  2 月前    · 
月球上的荔枝  ·  C'est tiguidou ...·  3 月前    · 
坚强的椅子  ·  Search | Valor Fitness·  2 年前    · 

I have some composable that uses a store. I would like to test the code with jest and mock the store with some predefined values. As we don't mount a composable I'm not sure how to proceed.

I was researching and just found some answers to Pinia but not for Vuex (like setActivePinia).

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.

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.