Test Utilities to help with Electron App Testing
MIT License
Electron test utils is a small utility to help test Electron apps that depend on currently untestable native desktop interactions. For instance the "dialog" module currently makes your code untestable if you use it.
npm i --save-dev electron-test-utils
It's really easy to use and integrates nicely into most test suites.
Your tests need access to the Electron API's, the easiest way to
achieve this is to use electron-mocha
Note: If you are running your tests with the --renderer
flag in electron-mocha
you also need to use the --require-main
flag and point it at electron-test-utils/build/main_inject
import { initialize, reset, utils } from 'electron-test-utils';
describe('my wonderful test suite', () => {
before(() => {
initialize();
});
it('should open a file after prompting the user', () => {
utils.dialog.nextOpenDialogCall(['path/to/file']);
// If this function requires openDialog it will be given ['path/to/file']
const file = myOpenFileFn();
file.should.be.equal('file_content');
});
afterEach(() => {
reset();
});
});
Note the two magic functions we call:
initialize()
hooks into Electron to makereset()
resets all return values and call values soCurrently we only support the following API's. Check out our module docs below.