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.spyOn() doesn't work with googleapis #3141

Closed
6 tasks done
Maxim-Mazurok opened this issue Apr 6, 2023 · 1 comment
Closed
6 tasks done

vi.spyOn() doesn't work with googleapis #3141

Maxim-Mazurok opened this issue Apr 6, 2023 · 1 comment

Comments

@Maxim-Mazurok
Copy link
Contributor

Describe the bug

I'm converting from jest.spyOn(google, "sheets").mockReturnValue({}); to vi.spyOn(google, "sheets").mockReturnValue({}); and it doesn't work - says that "sheets" is not assignable to "never".

Using the following patch (inspired by MethodLikeKeys from jest types) solves the issue:

diff --git a/node_modules/@vitest/spy/dist/index.d.ts b/node_modules/@vitest/spy/dist/index.d.ts
index ad13b9b..5428415 100644
--- a/node_modules/@vitest/spy/dist/index.d.ts
+++ b/node_modules/@vitest/spy/dist/index.d.ts
@@ -21,9 +21,9 @@ interface MockContext<TArgs, TReturns> {
     lastCall: TArgs | undefined;
 }
 type Procedure = (...args: any[]) => any;
-type Methods<T> = {
-    [K in keyof T]: T[K] extends Procedure ? K : never;
-}[keyof T] & (string | symbol);
+type Methods<T> = keyof {
+  [K in keyof T as T[K] extends Procedure ? K : never]: T[K];
+};
 type Properties<T> = {
     [K in keyof T]: T[K] extends Procedure ? never : K;
 }[keyof T] & (string | symbol);

This might be related: DefinitelyTyped/DefinitelyTyped#63182

Reproduction

ts
import { google } from "googleapis";
vi.spyOn(google, "sheets").mockReturnValue({});

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i9-12900H
    Memory: 30.94 GB / 63.68 GB
  Binaries:
    Node: 19.8.1 - ~\AppData\Local\nvs\node\19.8.1\x64\node.EXE
    npm: 9.5.1 - ~\AppData\Local\nvs\node\19.8.1\x64\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (111.0.1661.62)
    Internet Explorer: 11.0.19041.1566

Used Package Manager

npm

Validations

@Maxim-Mazurok
Copy link
Contributor Author

This was resolved by #3670

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

No branches or pull requests

2 participants