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

Types for mocked wrong for async functions when using partial flag. #3461

Closed
6 tasks done
ghry5 opened this issue May 29, 2023 · 1 comment · Fixed by #3462
Closed
6 tasks done

Types for mocked wrong for async functions when using partial flag. #3461

ghry5 opened this issue May 29, 2023 · 1 comment · Fixed by #3462

Comments

@ghry5
Copy link
Contributor

ghry5 commented May 29, 2023

Describe the bug

When using the vi.mocked helper with the partial flag the type for mockResolvedValue is incorrect for async functions.

 interface FooBar {
    foo: () => void;
    bar: () => boolean;
  }

  type FooBarAsyncFactory = () => Promise<FooBar>;

  const mockFactoryAsync: FooBarAsyncFactory = vi.fn();

  vi.mocked(mockFactoryAsync, { partial: true }).mockResolvedValue({
    foo: vi.fn(), // <- Throws Type error
  });

It currently expects: Partial<Promise<FooBar>> but should expect Promise<Partial<FooBar>>

Reproduction

An example can be viewed here: StackBlitz

System Info

System:
    OS: macOS 13.3.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 1.22 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.local/share/rtx/installs/node/18.16.0/bin/node
    npm: 9.5.1 - ~/.local/share/rtx/installs/node/18.16.0/bin/npm
    Watchman: 2023.05.22.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 113.0.5672.126
    Firefox: 110.0.1
    Safari: 16.4
  npmPackages:
    @vitest/browser: workspace:* => 0.31.1 
    @vitest/coverage-c8: workspace:* => 0.31.1 
    @vitest/coverage-istanbul: workspace:* => 0.31.1 
    @vitest/ui: workspace:* => 0.31.1 
    vite: ^4.2.1 => 4.2.1 
    vitest: workspace:* => 0.31.1

Used Package Manager

pnpm

Validations

@stackblitz
Copy link

stackblitz bot commented May 29, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant