vitest icon indicating copy to clipboard operation
vitest copied to clipboard

DeepPartial support in vi.mocked

Open Tsmith18256 opened this issue 1 year ago • 1 comments

Clear and concise description of the problem

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.

Alternative

No response

Additional context

No response

Validations

Tsmith18256 avatar Jun 12 '25 00:06 Tsmith18256

Feel free to open a PR with a fix. I think partial: true, deep: true should support that.

sheremet-va avatar Dec 22 '25 21:12 sheremet-va