admin管理员组

文章数量:1400837

currently I have the following situation with my React App using Zustand that I am testing with Vitest:

I have a parent controller component A and a child of that controller component B that both use a shared Zustand store S. I've written some tests for A with Vitest and React Testing Library, where I am mocking the child component B and using the actual store S (and resetting it between each test, ie each 'it' statement). However, if I were to create another describe block within the same file to test component B, how would I be able to do this if B has been mocked in the file? Since from what I understand mocks are hoisted in Vitest. Furthermore, if I put the tests for B in another file, from what I understand different Vitest files run in parallel, thus there could be an error due to them both accessing store S.

Does anyone know how best to resolve this? Thank you!

本文标签: reactjsTesting My React App with Zustand (or any state manager) QuestionStack Overflow