Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit 1539dd6

Browse files
committed
Added test to ensure console.warn called on error in loadImage().
1 parent da9ffca commit 1539dd6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/CacheableImage.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,40 @@ describe('CacheableImage', function() {
296296

297297
});
298298

299+
it('#_loadImage should warn developer on error getting local file path.', () => {
300+
301+
// Verify source uri prop only accepts web accessible urls.
302+
303+
const CacheableImage = imageCacheHoc(Image);
304+
305+
const imageUrl = 'https://img.wennermedia.com/5333a62d-07db-432a-92e2-198cafa38a14-326adb1a-d8ed-4a5d-b37e-5c88883e1989.png';
306+
307+
const cacheableImage = new CacheableImage({ // eslint-disable-line no-unused-vars
308+
source: {
309+
uri: imageUrl
310+
}
311+
});
312+
313+
const testError = new Error('Test error');
314+
315+
cacheableImage.fileSystem.getLocalFilePathFromUrl = () => {
316+
throw testError;
317+
};
318+
319+
// Cache console.warn
320+
const consoleWarnCache = console.warn; // eslint-disable-line no-console
321+
322+
console.warn = sinon.spy(); // eslint-disable-line no-console
323+
324+
cacheableImage._loadImage(imageUrl);
325+
326+
console.warn.should.be.calledWithExactly(testError); // eslint-disable-line no-console
327+
328+
// Re-apply console.warn
329+
console.warn = consoleWarnCache; // eslint-disable-line no-console
330+
331+
});
332+
299333
it('#render with valid props does not throw an error.', () => {
300334

301335
const CacheableImage = imageCacheHoc(Image);

0 commit comments

Comments
 (0)