-
I'm trying to mock the This class is used as a constructor I wrote mock and tests. And everything works. But I get a warning from the TypeScript, which is logical. // TS2339: Property 'mock' does not exist on type 'typeof BrowserWindow'.
expect(BrowserWindow.mock.instances.length).toBe(1); I tryed use // @ts-expect-error
const BrowserWindowMocked = BrowserWindow as MockedObject<typeof BrowserWindow>;
expect(BrowserWindowMocked.getAllWindows.mock.calls.length).toEqual(0); // Ok
// Property 'loadURL' does not exist on type '[options?: BrowserWindowConstructorOptions]'.
expect(BrowserWindowMocked.mock.instances[0].loadURL).toHaveBeenCalledTimes(1); My full demo can be founded here: https://github.com/cawa-93/vite-electron-builder/blob/3d81e3793da77ba56f40f5a5ad3531feb9568ee8/packages/main/tests/unit.spec.ts |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Type below works for me type TBrowserWindowMocked = typeof BrowserWindow
& MockedObjectDeep<typeof BrowserWindow>
& JestMockCompatFn<ConstructorParameters<typeof BrowserWindow>, MockedObjectDeep<BrowserWindow>>;
const BrowserWindowMocked = BrowserWindow as TBrowserWindowMocked Full test may be found here: https://github.com/cawa-93/vite-electron-builder/blob/cafa809218ae52a311beaee3bcc86f97abb3fabe/packages/main/tests/unit.spec.ts |
Beta Was this translation helpful? Give feedback.
Type below works for me
Full test may be found here: https://github.com/cawa-93/vite-electron-builder/blob/cafa809218ae52a311beaee3bcc86f97abb3fabe/packages/main/tests/unit.spec.ts