Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vi.mocked() with partial: true does the opposite of what's intended? #6781

Open
6 tasks done
kahagerman opened this issue Oct 23, 2024 · 1 comment · May be fixed by #6783
Open
6 tasks done

vi.mocked() with partial: true does the opposite of what's intended? #6781

kahagerman opened this issue Oct 23, 2024 · 1 comment · May be fixed by #6783

Comments

@kahagerman
Copy link

Describe the bug

I'm new to vitest/mocking in general, so please tell me if I'm misunderstanding the use case here.

To my understanding, this code should compile.

const mockedObject: ComplexInterface = vi.mocked({onlyOneProperty: "set"}, {partial: true})

From the original issue (#1739), the purpose of partial: true seems to be to allow defining only a few properties without typescript complaining.

But from what I can tell (simplifying the actual types somewhat), this function accepts the type T, and returns Partial<T>, where it should instead accept a Partial<T> and return T.

Am I simply misunderstanding this? (If so, it may be worth explaining these options better in the docs.)

Reproduction

N/A

System Info

N/A

Used Package Manager

pnpm

Validations

@kahagerman kahagerman changed the title vi.mocked with partial: true does the opposite of what's intended? vi.mocked() with partial: true does the opposite of what's intended? Oct 23, 2024
@sheremet-va
Copy link
Member

This works correctly. "mocked" is just a type hint noop, it doesn't do anything. You need pass down a spy, and partial will allow you to call mockReturnValue on it with incomplete data

@hi-ogawa hi-ogawa linked a pull request Oct 24, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants