fix: don't throw missing eta if eta is zero (#528)

The commit 0f8136f, which enforced validation for the state object,
introduced a subtle bug where `Missing state eta` would be thrown if
`eta === 0`, since `!0` evaluates to `true`.

This would cause the flashing to stop right at the end (when eta is
zero).

Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
Juan Cruz Viotti 2016-06-24 09:47:24 -04:00 committed by GitHub
parent 60b68d775b
commit d16d5469fd
2 changed files with 13 additions and 1 deletions

View File

@ -123,7 +123,7 @@ const storeReducer = (state, action) => {
throw new Error(`Invalid state percentage: ${action.data.percentage}`);
}
if (!action.data.eta) {
if (!action.data.eta && action.data.eta !== 0) {
throw new Error('Missing state eta');
}

View File

@ -138,6 +138,18 @@ describe('Browser: ImageWriter', function() {
}).to.throw('Missing state eta');
});
it('should not throw if eta is equal to zero', function() {
ImageWriterService.setFlashing(true);
m.chai.expect(function() {
ImageWriterService.setProgressState({
type: 'write',
percentage: 50,
eta: 0,
speed: 100000000000
});
}).to.not.throw('Missing state eta');
});
it('should throw if eta is not a number', function() {
ImageWriterService.setFlashing(true);
m.chai.expect(function() {