File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
packages/react-native-web/src/modules/ImageLoader Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,16 @@ describe('ImageLoader', () => {
3535 expect ( failureCallback ) . toHaveBeenCalledTimes ( 1 ) ;
3636 expect ( successCallback ) . toHaveBeenCalledTimes ( 0 ) ;
3737 } ) ;
38+
39+ test ( 'Failure callback is called when image fails to decode' , async ( ) => {
40+ window . Image = NotDecodingMockImage ;
41+ const successCallback = jest . fn ( ) ;
42+ const failureCallback = jest . fn ( ) ;
43+ ImageLoader . getSize ( testImage , successCallback , failureCallback ) ;
44+ await jest . runAllTimers ( ) ;
45+ expect ( failureCallback ) . toHaveBeenCalledTimes ( 1 ) ;
46+ expect ( successCallback ) . toHaveBeenCalledTimes ( 0 ) ;
47+ } ) ;
3848} ) ;
3949
4050class MockImage {
@@ -67,3 +77,9 @@ class NotLoadingMockImage extends MockImage {
6777 window . setTimeout ( this . onerror , 0 ) ;
6878 }
6979}
80+
81+ class NotDecodingMockImage extends MockImage {
82+ decode ( ) {
83+ return Promise . reject ( ) ;
84+ }
85+ }
Original file line number Diff line number Diff line change @@ -95,6 +95,8 @@ const ImageLoader = {
9595 const { naturalHeight, naturalWidth } = image ;
9696 if ( naturalHeight && naturalWidth ) {
9797 success ( naturalWidth , naturalHeight ) ;
98+ } else {
99+ errorCallback ( ) ;
98100 }
99101 }
100102 }
You can’t perform that action at this time.
0 commit comments