diff --git a/app/assets/javascripts/smart_interval.js b/app/assets/javascripts/smart_interval.js index f7cddc7e874..03fac82ac6d 100644 --- a/app/assets/javascripts/smart_interval.js +++ b/app/assets/javascripts/smart_interval.js @@ -5,7 +5,7 @@ export default class SmartInterval { /** - * @param { function } opts.callback A Promise, called on each iteration (required) unless still in progress + * @param { function } opts.callback Function that returns a promise, called on each iteration unless still in progress (required) * @param { milliseconds } opts.startingInterval `currentInterval` is set to this initially * @param { milliseconds } opts.maxInterval `currentInterval` will be incremented to this * @param { milliseconds } opts.hiddenInterval `currentInterval` is set to this @@ -113,8 +113,9 @@ export default class SmartInterval { .then(() => { this.isLoading = false; }) - .catch(() => { + .catch((err) => { this.isLoading = false; + throw new Error(err); }); } diff --git a/spec/javascripts/smart_interval_spec.js b/spec/javascripts/smart_interval_spec.js index 48d7f252b80..1c87fcec245 100644 --- a/spec/javascripts/smart_interval_spec.js +++ b/spec/javascripts/smart_interval_spec.js @@ -58,16 +58,19 @@ describe('SmartInterval', function () { }, DEFAULT_LONG_TIMEOUT); }); - it('does not increment while waiting for callback', function (done) { + it('does not increment while waiting for callback', function () { + jasmine.clock().install(); + const smartInterval = createDefaultSmartInterval({ callback: () => new Promise($.noop), }); - setTimeout(() => { - const oneInterval = smartInterval.cfg.startingInterval * DEFAULT_INCREMENT_FACTOR; - expect(smartInterval.getCurrentInterval()).toEqual(oneInterval); - done(); - }, DEFAULT_SHORT_TIMEOUT); + jasmine.clock().tick(DEFAULT_SHORT_TIMEOUT); + + const oneInterval = smartInterval.cfg.startingInterval * DEFAULT_INCREMENT_FACTOR; + expect(smartInterval.getCurrentInterval()).toEqual(oneInterval); + + jasmine.clock().uninstall(); }); });