@@ -249,6 +249,133 @@ describe('ReactNative', () => {
249
249
} ) ;
250
250
} ) ;
251
251
252
+ it ( 'should support reactTag in ref.measureLayout' , ( ) => {
253
+ const View = createReactNativeComponentClass ( 'RCTView' , ( ) => ( {
254
+ validAttributes : { foo : true } ,
255
+ uiViewClassName : 'RCTView' ,
256
+ } ) ) ;
257
+
258
+ class Subclass extends ReactNative . NativeComponent {
259
+ render ( ) {
260
+ return < View > { this . props . children } </ View > ;
261
+ }
262
+ }
263
+
264
+ const CreateClass = createReactClass ( {
265
+ mixins : [ NativeMethodsMixin ] ,
266
+ render ( ) {
267
+ return < View > { this . props . children } </ View > ;
268
+ } ,
269
+ } ) ;
270
+
271
+ [ View , Subclass , CreateClass ] . forEach ( Component => {
272
+ UIManager . measureLayout . mockReset ( ) ;
273
+
274
+ let viewRef ;
275
+ let otherRef ;
276
+ ReactNative . render (
277
+ < Component >
278
+ < Component
279
+ foo = "bar"
280
+ ref = { ref => {
281
+ viewRef = ref ;
282
+ } }
283
+ />
284
+ < Component
285
+ ref = { ref => {
286
+ otherRef = ref ;
287
+ } }
288
+ />
289
+ </ Component > ,
290
+ 11 ,
291
+ ) ;
292
+
293
+ expect ( UIManager . measureLayout ) . not . toBeCalled ( ) ;
294
+
295
+ const successCallback = jest . fn ( ) ;
296
+ const failureCallback = jest . fn ( ) ;
297
+ viewRef . measureLayout (
298
+ ReactNative . findNodeHandle ( otherRef ) ,
299
+ successCallback ,
300
+ failureCallback ,
301
+ ) ;
302
+
303
+ expect ( UIManager . measureLayout ) . toHaveBeenCalledTimes ( 1 ) ;
304
+ expect ( UIManager . measureLayout ) . toHaveBeenCalledWith (
305
+ expect . any ( Number ) ,
306
+ expect . any ( Number ) ,
307
+ expect . any ( Function ) ,
308
+ expect . any ( Function ) ,
309
+ ) ;
310
+
311
+ const args = UIManager . measureLayout . mock . calls [ 0 ] ;
312
+ expect ( args [ 0 ] ) . not . toEqual ( args [ 1 ] ) ;
313
+ expect ( successCallback ) . not . toBeCalled ( ) ;
314
+ expect ( failureCallback ) . not . toBeCalled ( ) ;
315
+ args [ 2 ] ( 'fail' ) ;
316
+ expect ( failureCallback ) . toBeCalledWith ( 'fail' ) ;
317
+
318
+ expect ( successCallback ) . not . toBeCalled ( ) ;
319
+ args [ 3 ] ( 'success' ) ;
320
+ expect ( successCallback ) . toBeCalledWith ( 'success' ) ;
321
+ } ) ;
322
+ } ) ;
323
+
324
+ it ( 'should support ref in ref.measureLayout of host components' , ( ) => {
325
+ const View = createReactNativeComponentClass ( 'RCTView' , ( ) => ( {
326
+ validAttributes : { foo : true } ,
327
+ uiViewClassName : 'RCTView' ,
328
+ } ) ) ;
329
+
330
+ [ View ] . forEach ( Component => {
331
+ UIManager . measureLayout . mockReset ( ) ;
332
+
333
+ let viewRef ;
334
+ let otherRef ;
335
+ ReactNative . render (
336
+ < Component >
337
+ < Component
338
+ foo = "bar"
339
+ ref = { ref => {
340
+ viewRef = ref ;
341
+ } }
342
+ />
343
+ < View
344
+ ref = { ref => {
345
+ otherRef = ref ;
346
+ } }
347
+ />
348
+ </ Component > ,
349
+ 11 ,
350
+ ) ;
351
+
352
+ expect ( UIManager . measureLayout ) . not . toBeCalled ( ) ;
353
+
354
+ const successCallback = jest . fn ( ) ;
355
+ const failureCallback = jest . fn ( ) ;
356
+ viewRef . measureLayout ( otherRef , successCallback , failureCallback ) ;
357
+
358
+ expect ( UIManager . measureLayout ) . toHaveBeenCalledTimes ( 1 ) ;
359
+ expect ( UIManager . measureLayout ) . toHaveBeenCalledWith (
360
+ expect . any ( Number ) ,
361
+ expect . any ( Number ) ,
362
+ expect . any ( Function ) ,
363
+ expect . any ( Function ) ,
364
+ ) ;
365
+
366
+ const args = UIManager . measureLayout . mock . calls [ 0 ] ;
367
+ expect ( args [ 0 ] ) . not . toEqual ( args [ 1 ] ) ;
368
+ expect ( successCallback ) . not . toBeCalled ( ) ;
369
+ expect ( failureCallback ) . not . toBeCalled ( ) ;
370
+ args [ 2 ] ( 'fail' ) ;
371
+ expect ( failureCallback ) . toBeCalledWith ( 'fail' ) ;
372
+
373
+ expect ( successCallback ) . not . toBeCalled ( ) ;
374
+ args [ 3 ] ( 'success' ) ;
375
+ expect ( successCallback ) . toBeCalledWith ( 'success' ) ;
376
+ } ) ;
377
+ } ) ;
378
+
252
379
it ( 'returns the correct instance and calls it in the callback' , ( ) => {
253
380
const View = createReactNativeComponentClass ( 'RCTView' , ( ) => ( {
254
381
validAttributes : { foo : true } ,
0 commit comments