File tree Expand file tree Collapse file tree 4 files changed +17
-8
lines changed Expand file tree Collapse file tree 4 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -222,12 +222,12 @@ test('returns composite UNSAFE_root', () => {
222222test ( 'container displays deprecation' ,  ( )  =>  { 
223223  const  view  =  render ( < View  testID = "inner"  /> ) ; 
224224
225-   expect ( ( )  =>  view . container ) . toThrowErrorMatchingInlineSnapshot ( ` 
225+   expect ( ( )  =>  ( view   as   any ) . container ) . toThrowErrorMatchingInlineSnapshot ( ` 
226226    "'container' property has been renamed to 'UNSAFE_root'. 
227227
228228    Consider using 'root' property which returns root host element." 
229229  ` ) ; 
230-   expect ( ( )  =>  screen . container ) . toThrowErrorMatchingInlineSnapshot ( ` 
230+   expect ( ( )  =>  ( screen   as   any ) . container ) . toThrowErrorMatchingInlineSnapshot ( ` 
231231    "'container' property has been renamed to 'UNSAFE_root'. 
232232
233233    Consider using 'root' property which returns root host element." 
@@ -238,3 +238,10 @@ test('RenderAPI type', () => {
238238  render ( < Banana  /> )  as  RenderAPI ; 
239239  expect ( true ) . toBeTruthy ( ) ; 
240240} ) ; 
241+ 
242+ test ( 'returned output can be spread using rest operator' ,  ( )  =>  { 
243+   // Next line should not throw 
244+   // eslint-disable-next-line @typescript-eslint/no-unused-vars 
245+   const  {  rerender,  ...rest  }  =  render ( < View  testID = "inner"  /> ) ; 
246+   expect ( rest ) . toBeTruthy ( ) ; 
247+ } ) ; 
Original file line number Diff line number Diff line change @@ -56,7 +56,6 @@ test('screen throws without render', () => {
5656  expect ( ( )  =>  screen . UNSAFE_root ) . toThrow ( 
5757    '`render` method has not been called' 
5858  ) ; 
59-   expect ( ( )  =>  screen . container ) . toThrow ( '`render` method has not been called' ) ; 
6059  expect ( ( )  =>  screen . debug ( ) ) . toThrow ( '`render` method has not been called' ) ; 
6160  expect ( ( )  =>  screen . debug . shallow ( ) ) . toThrow ( 
6261    '`render` method has not been called' 
Original file line number Diff line number Diff line change @@ -111,13 +111,19 @@ function buildRenderResult(
111111      return  getHostChildren ( instance ) [ 0 ] ; 
112112    } , 
113113    UNSAFE_root : instance , 
114-     get  container ( ) : ReactTestInstance  { 
114+   } ; 
115+ 
116+   // Add as non-enumerable property, so that it's safe to enumerate 
117+   // `render` result, e.g. using destructuring rest syntax. 
118+   Object . defineProperty ( result ,  'container' ,  { 
119+     enumerable : false , 
120+     get ( )  { 
115121      throw  new  Error ( 
116122        "'container' property has been renamed to 'UNSAFE_root'.\n\n"  + 
117123          "Consider using 'root' property which returns root host element." 
118124      ) ; 
119125    } , 
120-   } ; 
126+   } ) ; 
121127
122128  setRenderResult ( result ) ; 
123129  return  result ; 
Original file line number Diff line number Diff line change @@ -13,9 +13,6 @@ const notImplementedDebug = () => {
1313notImplementedDebug . shallow  =  notImplemented ; 
1414
1515const  defaultScreen : RenderResult  =  { 
16-   get  container ( ) : ReactTestInstance  { 
17-     throw  new  Error ( SCREEN_ERROR ) ; 
18-   } , 
1916  get  root ( ) : ReactTestInstance  { 
2017    throw  new  Error ( SCREEN_ERROR ) ; 
2118  } , 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments