test: improve test isolation in unit tests#8528
Conversation
|
Thank you for the PR. But what issue are you trying to address with this PR? |
|
This PR addresses potential test isolation issues and mock state leakage in the unit test suite. By default, Vitest retains call histories and implementation states for mocks (e.g. Without resetting or clearing mocks after each test, assertions such as |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Unless there is an actual, reproduce-able issue, I'm going to say this is not needed. We don't just add code for "potential issues". |
Implemented a global afterEach hook in tests/javascript/unit/setup.js to call vi.clearAllMocks() after each test. This ensures that mocks are cleared between test executions, preventing state leakage and ensuring cleaner test isolation, which is critical for robust and reliable test suites. This change adheres to testing best practices for maintaining clean mock state.