I m trying to build an application using Electron.
I need to make some unit test based on the electron env and using electron packages.
This way, I m using spectron to simulate my application.
On the documentation, it's written that I have to put in 'path' property the path where my executable file is. I don't have executable for now, I m in development mode.
Here's what I've tried based on another question :
beforeEach(() => {
app = new Application({
path: 'node_modules/.bin/electron'
});
app.start().then(res => console.log(res), err => console.log(err));
});
Nothing appears on the prompt and the following test is failing telling that I can't get getWindowCount on an undefined object (clearly, the app isn't instantiated) :
it('should call currentWindow', (done) => {
app.client.getWindowCount().then((count) => {
expect(count).to.equals(1);
done();
});
});
Does anybody knows what should I put in this path to make my test env work ?
PS : I m using mocha chai and sinon.
Thanks for your help
At first I was creating an executable for the purpose of testing, but that's actually not necessary.
You can see that Spectron has an example test and a global setup.
The example passes an option called args, and that’s exactly what you are missing. This is what I am doing:
var appPath = path.resolve(__dirname, '../'); //require the whole thing
var electronPath = path.resolve(__dirname, '../node_modules/.bin/electron');
beforeEach(function() {
myApp = new Application({
path: electronPath,
args: [appPath], // pass args along with path
});
return myApp.start().then(function() {
assert.equal(myApp.isRunning(), true);
chaiAsPromised.transferPromiseness = myApp.transferPromiseness;
return myApp;
});
});
My test sits in ./tests/app-test.js. The above works for me.