From 1de741e9f9920e62af59ff4768f112e61360c89a Mon Sep 17 00:00:00 2001 From: MinhHNguyen Date: Mon, 28 Aug 2017 16:56:32 -0700 Subject: [PATCH] Fix: pass get failure through in case imageEl is a div of images (#338) --- src/lib/viewers/image/ImageBaseViewer.js | 10 +++++----- .../viewers/image/__tests__/ImageBaseViewer-test.js | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/lib/viewers/image/ImageBaseViewer.js b/src/lib/viewers/image/ImageBaseViewer.js index 77ae4e189..c7797c268 100644 --- a/src/lib/viewers/image/ImageBaseViewer.js +++ b/src/lib/viewers/image/ImageBaseViewer.js @@ -178,11 +178,11 @@ class ImageBaseViewer extends BaseViewer { * naturalHeight and naturalWidth attributes work correctly in IE 11. * * @private - * @param {Image} imageEl - The image to set the original size attributes on + * @param {HTMLElement} imageEl - The image to set the original size attributes on * @return {Promise} A promise that is resolved if the original image dimensions were set. */ setOriginalImageSize(imageEl) { - const promise = new Promise((resolve, reject) => { + const promise = new Promise((resolve) => { // Do not bother loading a new image when the natural size attributes exist if (imageEl.naturalWidth && imageEl.naturalHeight) { imageEl.setAttribute('originalWidth', imageEl.naturalWidth); @@ -205,15 +205,15 @@ class ImageBaseViewer extends BaseViewer { const aspectRatio = h ? w / h : w; imageEl.setAttribute('originalWidth', Math.round(aspectRatio * 150)); imageEl.setAttribute('originalHeight', 150); - resolve(); } catch (e) { // Assume 300x150 that chrome does by default imageEl.setAttribute('originalWidth', 300); imageEl.setAttribute('originalHeight', 150); - resolve(e); + } finally { + resolve(); } }) - .catch(reject); + .catch(resolve); } }); diff --git a/src/lib/viewers/image/__tests__/ImageBaseViewer-test.js b/src/lib/viewers/image/__tests__/ImageBaseViewer-test.js index 50c8831f4..a40751e85 100644 --- a/src/lib/viewers/image/__tests__/ImageBaseViewer-test.js +++ b/src/lib/viewers/image/__tests__/ImageBaseViewer-test.js @@ -260,6 +260,17 @@ describe('lib/viewers/image/ImageBaseViewer', () => { Assert.fail(); }); }); + + it('should resolve when the get call fails', (done) => { + const imageEl = {}; + const getStub = sandbox.stub(util, 'get').returns(Promise.reject()); + const promise = imageBase.setOriginalImageSize(imageEl); + promise.should.be.fulfilled.then(() => { + done(); + }).catch(() => { + Assert.fail(); + }); + }); }); describe('bindControlListeners()', () => {