@@ -171,6 +171,38 @@ describe('components/Image', () => {
171
171
expect ( onLoadEndStub . mock . calls . length ) . toBe ( 2 ) ;
172
172
} ) ;
173
173
174
+ test ( 'is called on update if "headers" are different' , ( ) => {
175
+ const onLoadStartStub = jest . fn ( ) ;
176
+ const onLoadStub = jest . fn ( ) ;
177
+ const onLoadEndStub = jest . fn ( ) ;
178
+ const { rerender } = render (
179
+ < Image
180
+ onLoad = { onLoadStub }
181
+ onLoadEnd = { onLoadEndStub }
182
+ onLoadStart = { onLoadStartStub }
183
+ source = { {
184
+ uri : 'https://test.com/img.jpg' ,
185
+ headers : { 'x-custom-header' : 'abc123' }
186
+ } }
187
+ />
188
+ ) ;
189
+ act ( ( ) => {
190
+ rerender (
191
+ < Image
192
+ onLoad = { onLoadStub }
193
+ onLoadEnd = { onLoadEndStub }
194
+ onLoadStart = { onLoadStartStub }
195
+ source = { {
196
+ uri : 'https://test.com/img.jpg' ,
197
+ headers : { 'x-custom-header' : '123abc' }
198
+ } }
199
+ />
200
+ ) ;
201
+ } ) ;
202
+ expect ( onLoadStub . mock . calls . length ) . toBe ( 2 ) ;
203
+ expect ( onLoadEndStub . mock . calls . length ) . toBe ( 2 ) ;
204
+ } ) ;
205
+
174
206
test ( 'is not called on update if "uri" is the same' , ( ) => {
175
207
const onLoadStartStub = jest . fn ( ) ;
176
208
const onLoadStub = jest . fn ( ) ;
@@ -222,6 +254,42 @@ describe('components/Image', () => {
222
254
expect ( onLoadStub . mock . calls . length ) . toBe ( 1 ) ;
223
255
expect ( onLoadEndStub . mock . calls . length ) . toBe ( 1 ) ;
224
256
} ) ;
257
+
258
+ test ( 'is not called on update if "headers" and "uri" the same' , ( ) => {
259
+ const onLoadStartStub = jest . fn ( ) ;
260
+ const onLoadStub = jest . fn ( ) ;
261
+ const onLoadEndStub = jest . fn ( ) ;
262
+ const { rerender } = render (
263
+ < Image
264
+ onLoad = { onLoadStub }
265
+ onLoadEnd = { onLoadEndStub }
266
+ onLoadStart = { onLoadStartStub }
267
+ source = { {
268
+ uri : 'https://test.com/img.jpg' ,
269
+ width : 1 ,
270
+ height : 1 ,
271
+ headers : { 'x-custom-header' : 'abc123' }
272
+ } }
273
+ />
274
+ ) ;
275
+ act ( ( ) => {
276
+ rerender (
277
+ < Image
278
+ onLoad = { onLoadStub }
279
+ onLoadEnd = { onLoadEndStub }
280
+ onLoadStart = { onLoadStartStub }
281
+ source = { {
282
+ uri : 'https://test.com/img.jpg' ,
283
+ width : 1 ,
284
+ height : 1 ,
285
+ headers : { 'x-custom-header' : 'abc123' }
286
+ } }
287
+ />
288
+ ) ;
289
+ } ) ;
290
+ expect ( onLoadStub . mock . calls . length ) . toBe ( 1 ) ;
291
+ expect ( onLoadEndStub . mock . calls . length ) . toBe ( 1 ) ;
292
+ } ) ;
225
293
} ) ;
226
294
227
295
describe ( 'prop "resizeMode"' , ( ) => {
@@ -242,7 +310,8 @@ describe('components/Image', () => {
242
310
'' ,
243
311
{ } ,
244
312
{ uri : '' } ,
245
- { uri : 'https://google.com' }
313
+ { uri : 'https://google.com' } ,
314
+ { uri : 'https://google.com' , headers : { 'x-custom-header' : 'abc123' } }
246
315
] ;
247
316
sources . forEach ( ( source ) => {
248
317
expect ( ( ) => render ( < Image source = { source } /> ) ) . not . toThrow ( ) ;
@@ -338,6 +407,31 @@ describe('components/Image', () => {
338
407
'http://localhost/static/[email protected] '
339
408
) ;
340
409
} ) ;
410
+
411
+ test ( 'it correctly passes headers to ImageLoader' , ( ) => {
412
+ const uri = 'https://google.com/favicon.ico' ;
413
+ const headers = { 'x-custom-header' : 'abc123' } ;
414
+ const source = { uri, headers } ;
415
+ render ( < Image source = { source } /> ) ;
416
+
417
+ expect ( ImageLoader . load ) . toHaveBeenCalledWith (
418
+ expect . objectContaining ( { headers } ) ,
419
+ expect . any ( Function ) ,
420
+ expect . any ( Function )
421
+ ) ;
422
+ } ) ;
423
+
424
+ test ( 'it correctly passes uri to ImageLoader' , ( ) => {
425
+ const uri = 'https://google.com/favicon.ico' ;
426
+ const source = { uri } ;
427
+ render ( < Image source = { source } /> ) ;
428
+
429
+ expect ( ImageLoader . load ) . toHaveBeenCalledWith (
430
+ expect . objectContaining ( { uri } ) ,
431
+ expect . any ( Function ) ,
432
+ expect . any ( Function )
433
+ ) ;
434
+ } ) ;
341
435
} ) ;
342
436
343
437
describe ( 'prop "style"' , ( ) => {
0 commit comments