How to initialize store before component mount in tests #828
-
In cookbook I see this example:
But what if I need to set store values before component mount? For example, if component uses store values in |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
you can create the testing pinia before: const pinia = createTestingPinia()
pinia.state.value[storeId] = {
// initial state for the store
}
mount(Counter, { global: { plugins: [pinia] }}) |
Beta Was this translation helpful? Give feedback.
-
@Djaler sorry, for jumping on to your post. I was hoping you might have gotten this bit of code to work in your tests:
I'm trying to get it working in my test, but am stuck on how to modify it from the guide/tutorial so that it works for my test. In case you want further context: #1540 Thank you for your time 🙏 |
Beta Was this translation helpful? Give feedback.
-
Alternative way is to pass values directly to
|
Beta Was this translation helpful? Give feedback.
-
I found a solution which is good enough for me. You can change the values after the component is mounted and then re-render it
|
Beta Was this translation helpful? Give feedback.
you can create the testing pinia before: