Skip to content

DeepPartial support in vi.mocked #8152

@Tsmith18256

Description

@Tsmith18256

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions