Skip to content

Commit

Permalink
Fix: pass get failure through in case imageEl is a div of images (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
Minh-Ng authored Aug 28, 2017
1 parent c6dac8a commit 1de741e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/lib/viewers/image/ImageBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
});

Expand Down
11 changes: 11 additions & 0 deletions src/lib/viewers/image/__tests__/ImageBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down

0 comments on commit 1de741e

Please sign in to comment.