-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
Describe the bug
Function mocking through .mockImplementation(Once) allows an incorrect Promise-wrapped type to be returned. For example, a function that returns number can be mocked to return Promise<number> as opposed to number. This is possible because .mockImplementation(Once) accepts an union-type of number | 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 allows number.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-bayh5s?file=index.test.ts
System Info
System:
OS: Linux 5.19 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
CPU: (12) x64 12th Gen Intel(R) Core(TM) i7-1255U
Memory: 9.74 GB / 15.26 GB
Container: Yes
Shell: 5.8.1 - /usr/bin/zsh
Binaries:
Node: 18.16.1
npm: 9.5.1
pnpm: 8.6.1
npmPackages:
vite: ^4.3.9 => 4.3.9
vitest: ^0.32.4 => 0.32.4Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels