cd into project and install dependencies with $ yarn
Run tests: $ yarn vitest
Expected behavior
Test should pass as spied function is called by watcher, and tallies value is updated correctly.
Actual behavior
Additional information
We use the setup syntax exclusively at my company, but have been unable to get good unit tests going for our Pinia stores, as functions returned from the setup store don't seem to be spied correctly when called from watch, or if called from another function in the setup store.
For example, if I have a store with 2 functions, where one function calls another:
function thing1() {
if (myValue === true) return thing2();
}
function thing2() {
console.log("THING 2");
}
Spying on thing2 i.e. const spy = vi.spyOn(store, "thing2") does not work properly. If I call thing1(), my test will fail as the thing2 spy will not record as having been called.
The same behavior occurs if I were to call thing2 from a watcher as shown in the example repo.
Reproduction
https://github.com/bearguns/pinia-setup-store-testing-bug
Steps to reproduce the bug
cd
into project and install dependencies with$ yarn
$ yarn vitest
Expected behavior
Test should pass as spied function is called by watcher, and
tallies
value is updated correctly.Actual behavior
Additional information
We use the setup syntax exclusively at my company, but have been unable to get good unit tests going for our Pinia stores, as functions returned from the setup store don't seem to be spied correctly when called from
watch
, or if called from another function in the setup store.For example, if I have a store with 2 functions, where one function calls another:
Spying on
thing2
i.e.const spy = vi.spyOn(store, "thing2")
does not work properly. If I callthing1()
, my test will fail as thething2
spy will not record as having been called.The same behavior occurs if I were to call
thing2
from a watcher as shown in the example repo.