Mocking implementation with mockImplementation allows incorrect return types
#3750
Closed
6 tasks done
Describe the bug
Function mocking through
.mockImplementation(Once)allows an incorrect Promise-wrapped type to be returned. For example, a function that returnsnumbercan be mocked to returnPromise<number>as opposed tonumber. This is possible because.mockImplementation(Once)accepts an union-type ofnumber | Promise<number>as the return type for the implementation.Jest, a test runner with similar API doesn't allow
Promise<number>to be returned by the mocked implementation and only allowsnumber.Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-bayh5s?file=index.test.ts
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: