diff --git a/lib/src/dialog.js b/lib/src/dialog.js index ee0d81b0..2015ced7 100644 --- a/lib/src/dialog.js +++ b/lib/src/dialog.js @@ -54,9 +54,11 @@ exports.selectImage = function() { ] } ] - }, resolve); + }, function(files) { + return resolve(files || []); + }); }).get(0).then(function(file) { - if (zipImage.isZip(file) && !zipImage.isValidZipImage(file)) { + if (file && zipImage.isZip(file) && !zipImage.isValidZipImage(file)) { electron.dialog.showErrorBox( 'Invalid zip image', `${packageJSON.displayName} can only open Zip archives that contain exactly one image file inside.` diff --git a/tests/src/dialog.spec.js b/tests/src/dialog.spec.js index d88d7924..4f577ece 100644 --- a/tests/src/dialog.spec.js +++ b/tests/src/dialog.spec.js @@ -8,6 +8,24 @@ describe('Dialog:', function() { describe('.selectImage()', function() { + describe('given the user does not select anything', function() { + + beforeEach(function() { + this.showOpenDialogStub = m.sinon.stub(electron.dialog, 'showOpenDialog'); + this.showOpenDialogStub.yields(undefined); + }); + + afterEach(function() { + this.showOpenDialogStub.restore(); + }); + + it('should eventually be undefined', function() { + const promise = dialog.selectImage(); + m.chai.expect(promise).to.eventually.be.undefined; + }); + + }); + describe('given the users performs a selection', function() { beforeEach(function() {