Skip to content

refactor!: remove original impl workaround for Vitest 3#45

Open
mcous wants to merge 1 commit into
v1from
v1-cleanup
Open

refactor!: remove original impl workaround for Vitest 3#45
mcous wants to merge 1 commit into
v1from
v1-cleanup

Conversation

@mcous
Copy link
Copy Markdown
Owner

@mcous mcous commented Apr 24, 2026

Since Vitest v4 has now been released (and Vitest v5 is on the way) this PR removes the workaround mockReset in Vitest v3 added in #28. The fix moving forward for users is to upgrade to Vitest >= v4

BREAKING CHANGE: When using Vitest v3, the mock implementation fallback may not work properly after a mockReset. Upgrade to Vitest v4 to resolve

@mcous
Copy link
Copy Markdown
Owner Author

mcous commented Apr 25, 2026

Changed my mind on this one, I think the hack is still valuable as long as we support vitest v3

@mcous mcous closed this Apr 25, 2026
@mcous
Copy link
Copy Markdown
Owner Author

mcous commented Apr 27, 2026

I keep flipping back and forth here

Keep it

  • Pro: Prevents silent breakage for v3 users who follow vitest-when's own mockReset recommendation with vi.fn(() => impl). Failure mode is confusing — looks like a vitest-when bug, not a Vitest bug.
  • Con: Introduces unintended behavior — vi.spyOn mocks fall back to the real implementation. This silently disappears on v4, making the hack itself a source of breaking changes across Vitest upgrades.

Remove it

  • Pro: Eliminates the unintended spyOn fallback. Cleaner, smaller code. Unintended behavior can't be preserved on v4 anyway, so carrying it in v3 only creates a hidden migration trap.
  • Con: v3 users following the docs (mockReset + initial implementation) hit a confusing failure that looks like a vitest-when regression
    • Mitigation: changelog note pointing to Vitest v4 upgrade.

Conclusion

My gut says to remove the hack for v1 - it's less code to maintain and removes a source of unintended behavior

@mcous mcous reopened this Apr 27, 2026
BREAKING CHANGE: When using Vitest v3, the fallback mock implementation
will be lost after `mockReset`. This is a bug in Vitest. To resolve,
upgrade to Vitest v4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant