Skip to content

How to create a Mock object of ipcMain to run tests #726

Answered by cawa-93
Ghost295 asked this question in Q&A
Discussion options

You must be logged in to vote

You should mock all electron module exports. Example for BrowserWindow class:

vi.mock('electron', () => {
const bw = vi.fn() as MaybeMocked<typeof BrowserWindow>;
// @ts-expect-error It's work in runtime, but I Haven't idea how to fix this type error
bw.getAllWindows = vi.fn(() => bw.mock.instances);
bw.prototype.loadURL = vi.fn();
bw.prototype.on = vi.fn();
bw.prototype.destroy = vi.fn();
bw.prototype.isDestroyed = vi.fn();
bw.prototype.isMinimized = vi.fn();
bw.prototype.focus = vi.fn();
bw.prototype.restore = vi.fn();
return {Brow…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Ghost295
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants