vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Mocking implementation of function returning a PromiseLike object partially work

Open LeSuisse opened this issue 3 years ago • 2 comments

Describe the bug

My use case is trying to mock a function returning a ResultAsync object from the neverthrow library. The ResultAsync object is an implementation of a PromiseLike interface which adds a few methods to the objects to help processing them. When mocking the implementation via vi.spyOn().mockImplementation() it seems that I can still await the promises as expected but I cannot use the additional methods without getting a TypeError.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-fdcijn?file=test/spy.test.ts

System Info

❯ npx envinfo --system --npmPackages '{vitest,vite,@vitejs/*}' --binaries --browsers
success Install finished in 0.977s


  System:
    OS: Linux 5.0 undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /bin/yarn
    npm: 7.17.0 - /bin/npm
  npmPackages:
    vitest: ^0.21.1 => 0.21.1

Used Package Manager

npm

Validations

LeSuisse avatar Aug 10 '22 08:08 LeSuisse

I think this is the same reason with #1767

PatrickChen928 avatar Aug 11 '22 01:08 PatrickChen928

Good catch that's likely the case :+1:

LeSuisse avatar Aug 11 '22 09:08 LeSuisse

Issue appears to be fixed in 0.25.3 (not sure exactly which specific version did fix it though).

LeSuisse avatar Nov 23 '22 12:11 LeSuisse