Electron App Testing Guide (Desktop Apps)
Electron apps bundle Chromium and Node into a native-like desktop app. They are JavaScript-first with access to OS-level APIs. Testing them combines web testing (for the renderer) with Node and IPC te
Electron apps bundle Chromium and Node into a native-like desktop app. They are JavaScript-first with access to OS-level APIs. Testing them combines web testing (for the renderer) with Node and IPC testing (for the main process). This guide covers the 2026 approach.
What Electron is
- Main process: Node.js, manages windows, access OS
- Renderer process: Chromium, the UI you see
- Preload script: bridge between main and renderer via contextBridge
- IPC: inter-process communication
Testing each tier matters.
Unit tests
Renderer code (React / Vue / etc.)
Jest / Vitest like any web app. Mock window.electronAPI:
global.electronAPI = {
saveFile: jest.fn(() => Promise.resolve({path: '/tmp/saved.txt'})),
loadFile: jest.fn(() => Promise.resolve('content'))
};
Main process code
Jest in Node environment. Mock electron module:
jest.mock('electron', () => ({
app: { whenReady: jest.fn(() => Promise.resolve()) },
BrowserWindow: jest.fn(() => ({ loadURL: jest.fn(), webContents: { send: jest.fn() } })),
ipcMain: { handle: jest.fn() }
}));
IPC / contextBridge
Test each exposed API:
test('save-file invokes IPC with content', async () => {
const mockSend = jest.fn(() => Promise.resolve({path: 'out.txt'}));
const api = createElectronAPI(mockSend);
const result = await api.saveFile('hello');
expect(mockSend).toHaveBeenCalledWith('save-file', 'hello');
});
End-to-end with Playwright
Playwright supports Electron directly:
import { _electron as electron } from '@playwright/test';
test('app launches and saves file', async () => {
const app = await electron.launch({ args: ['.'] });
const window = await app.firstWindow();
await window.click('text=New Document');
await window.fill('[contenteditable]', 'Hello');
await window.click('text=Save');
// Assert saved state
await window.waitForSelector('text=Saved');
await app.close();
});
Works cross-platform (Linux / macOS / Windows runners).
Spectron (deprecated)
Older tool, no longer maintained. Use Playwright's Electron support.
Test strategy
- Renderer unit tests: majority. Fast.
- Main process unit tests: business logic. Fast.
- IPC contract tests: API correctness across boundary.
- Playwright E2E: critical flows. Slower.
Auto-update testing
Electron apps update themselves. Test:
- Check for update on launch
- Download update
- Prompt user to restart
- Apply update
Harder to automate fully; manual pass per release on auto-update code.
Platform specifics
macOS
- App Sandbox
- Code signing required for distribution
- Notarization
- Dock menu, menu bar
Windows
- Installer (NSIS, Squirrel, MSI)
- Code signing (Authenticode)
- Windows Store submission
Linux
- Multiple formats: .deb, .rpm, AppImage, Snap, Flatpak
- Distro-specific paths
Test each platform's install / uninstall / update cycle.
Security
contextIsolation: truenodeIntegration: false- Use
contextBridgefor exposed API - Sandbox renderer
- Sign binaries
- Verify update signatures
Security audit per release — Electron carries Chromium's CVE surface.
Accessibility
Electron uses Chromium's accessibility. Similar to web:
- ARIA roles and labels
- Keyboard navigation
- Screen reader (NVDA, VoiceOver, Narrator)
Test with platform-native screen readers.
How SUSA tests Electron
SUSA can drive Electron apps similarly to web apps via Playwright's Electron support. For dedicated desktop automation at scale, SUSA integrates with Playwright's _electron.launch().
# Example (pseudo — Electron testing is a niche path)
susatest-agent test path/to/electron/app --framework electron --steps 200
Common bugs
- Memory leak in renderer — Electron keeps renderer process alive; leaks accumulate
- IPC race: multiple concurrent invokes with same channel
- Menu item disabled when it should be enabled — state not propagated
- Window close asks "save" even with no changes — dirty state wrong
- Cross-platform path handling —
/vs\, case sensitivity
Electron is powerful but bloated. Test discipline keeps desktop apps stable.
Test Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free