Testing: best practices for customizing actions and getters? #1388
Replies: 4 comments 2 replies
-
Thank you for posting your solution! I got it working with your workaround <3 |
Beta Was this translation helpful? Give feedback.
-
It would be ideal if we could define getters/actions in the same way that we currently set the |
Beta Was this translation helpful? Give feedback.
-
Restarting this discussion as I'm struggling doing the same. (see #1848) @marina-mosti @mruthh How did you finally manage to deal with that? |
Beta Was this translation helpful? Give feedback.
-
@leo-coco See my answer here, it might be helpful |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am testing components that depend on a pinia store and that call actions from the pinia store on an
onBeforeMount
hook.In my tests, I need to be able to customize the returned or resolved values of those actions. I know I can set the initial state with the
initialState
property, and I know from #1292 that for actions that don't run immediately, I can customize the mock implementation usingstore.action.mockImplementation()
.However, for actions that run before the component mounts, I can't access the returned
store.action
soon enough to customize the initial return value.I have learned I can use the
fakeApp
property to be able to customize the actions sooner, but from the docs, this doesn't seem to be the intended use offakeApp
. Is usingfakeApp
as shown below a best practice, or is there a better approach to customizing actions in testing?This question also applies to getters. Is there a best practice in testing for customizing getters that a component accesses on or before being mounted?
Beta Was this translation helpful? Give feedback.
All reactions