Fix sporadic Cannot read property 'then' of undefined

This error happened when trying to burn an image when there is already a
burn in progress.

Fixes: https://github.com/resin-io/resin-etcher/issues/96
This commit is contained in:
Juan Cruz Viotti 2016-01-22 12:41:43 -04:00
parent 9d68199ecd
commit 111529ee71
2 changed files with 15 additions and 3 deletions

View File

@ -114,10 +114,8 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
* });
*/
this.burn = function(image, drive, onProgress) {
// Avoid writing more than once
if (self.isBurning()) {
return;
return $q.reject(new Error('There is already a burn in progress'));
}
self.setBurning(true);

View File

@ -84,6 +84,20 @@ describe('Browser: ImageWriter', function() {
m.chai.expect(this.performWriteStub).to.have.been.calledOnce;
});
it('should reject the second burn attempt', function() {
ImageWriterService.burn('foo.img', '/dev/disk2');
let rejectError = null;
ImageWriterService.burn('foo.img', '/dev/disk2').catch(function(error) {
rejectError = error;
});
$rootScope.$apply();
m.chai.expect(rejectError).to.be.an.instanceof(Error);
m.chai.expect(rejectError.message).to.equal('There is already a burn in progress');
});
});
describe('given an unsuccesful write', function() {