Objects deleted from stores re-appearing while running tests #2666
-
ContextI have some code that is using Because the tests mutate state, this must be reset in some way between tests. As far as I understand it, there's no way to create a "fresh" store for each test within a given test file. In addition, there's no ProblemIn order to start from the same state for each test, any changes are reverted in the Question(s)
I've included a pared down copy of the relevant code to illustrate this - just install the deps in your preferred way and run the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Yes, create a new pinia for each test (https://pinia.vuejs.org/cookbook/testing.html#Unit-testing-a-store) |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply and taking a look at this. OK, so |
Beta Was this translation helpful? Give feedback.
The problem is your
defaultFormations
. It's reused for all stores because it's a reference in js. Create a copy withref({ ...defaultFormations })
or export a function that returns a fresh object rather than the object itself.