You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The vi.mocked type helper currently only supports partials at the surface level. If the return type of a function contains nested objects, there's no way to do a deep/recursive partial. This can require mocking a lot of unnecessary fields.
Particularly with APIs that return a tuple of a success object and an error (eg: [data, err]). The partial flag doesn't really do anything here, data must still be fully mocked to pass the type checks.
Suggested solution
I would be happy to send in a PR to add support for a DeepPartial. I would be looking for some guidance on what the ideal API for that would be in the options object of vi.mocked. I had originally expected setting { partial: true, deep: true } to do what I'm describing, so it's going to be tricky to add a flag that's clear in what it does and what separates it from the existing flags.
Activity
sheremet-va commentedon Dec 22, 2025
Feel free to open a PR with a fix. I think
partial: true, deep: trueshould support that.feat(spy): support deep partial in vi.mocked (vitest-dev#8152)
docs(vi): add deep partial example for vi.mocked (vitest-dev#8152)
fix(spy): support deep partial in vi.mocked (#8152) (#9493)