Does initial state work with setup stores for testing/pinia? #2028
-
Trying to migrate to pinia and nearly there but hitting issues with trying to mock my setup stores. I have a userStore that is a setup store. It returns a user ref at the end of the store. Now I want to set the initial value of this user for a test but https://pinia.vuejs.org/cookbook/testing.html#initial-state does not seem to be woriking #1835 (comment) found this which points in the direction I thought I needed to go, but documentation is not clear about this kind of issues and is the biggest pain point when using pinia. IMO setup stores fit really nicely with vuejs composition API and would be great if I could set the initial state/getters without having to @ts-gnore the typescript errors. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
initial state should work for both setup and option stores. Are you sure you are calling |
Beta Was this translation helpful? Give feedback.
initial state should work for both setup and option stores. Are you sure you are calling
useStore()
after mounting? like shown at https://pinia.vuejs.org/cookbook/testing.html#initial-state ? Otherwise you will need to pass the testing pinia to theuseStore()
function. You can see an example at https://pinia.vuejs.org/cookbook/testing.html#mocking-getters although the real explanation is at https://pinia.vuejs.org/ssr/