From 2ee39a075fa2180aa1264e9dd326b07ed15c0688 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Tue, 5 May 2026 15:32:35 -0400 Subject: [PATCH 1/2] test: re-enable test for preventing new windows Assisted-by: Claude Opus 4.6 --- tests/main/windows.spec.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/main/windows.spec.ts b/tests/main/windows.spec.ts index 04102d83a6..ac187749cf 100644 --- a/tests/main/windows.spec.ts +++ b/tests/main/windows.spec.ts @@ -108,16 +108,18 @@ describe('windows', () => { expect(createContextMenu).toHaveBeenCalled(); }); - // FIXME: new test for setWindowOpenHandler - it.skip('prevents new-window"', async () => { - const e = { - preventDefault: vi.fn(), - }; - + it('sets a window open handler that denies and opens URL externally', async () => { await getOrCreateMainWindow(); - expect(browserWindows[0]).toBeTruthy(); - (await getOrCreateMainWindow()).webContents.emit('new-window', e); - expect(e.preventDefault).toHaveBeenCalled(); + const win = browserWindows[0]!; + const handler = vi.mocked(win.webContents.setWindowOpenHandler).mock + .calls[0][0]; + const result = handler({ + url: 'https://example.com', + } as Electron.HandlerDetails); + expect(result).toEqual({ action: 'deny' }); + expect(electron.shell.openExternal).toHaveBeenCalledWith( + 'https://example.com', + ); }); it('prevents will-navigate"', async () => { From 218830d3aa62252acf59d02cefb26702aa279ee5 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Tue, 5 May 2026 15:49:09 -0400 Subject: [PATCH 2/2] test: fix test running after others --- tests/main/windows.spec.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/main/windows.spec.ts b/tests/main/windows.spec.ts index ac187749cf..b7626e4b74 100644 --- a/tests/main/windows.spec.ts +++ b/tests/main/windows.spec.ts @@ -88,6 +88,11 @@ describe('windows', () => { }); describe('getOrCreateMainWindow()', () => { + beforeEach(async () => { + const window = await getOrCreateMainWindow(); + window.emit('closed'); + }); + it('creates a window on first call', async () => { expect(browserWindows.length).toBe(0); await getOrCreateMainWindow();