File tree 4 files changed +17
-8
lines changed
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', () => {
222
222
test ( 'container displays deprecation' , ( ) => {
223
223
const view = render ( < View testID = "inner" /> ) ;
224
224
225
- expect ( ( ) => view . container ) . toThrowErrorMatchingInlineSnapshot ( `
225
+ expect ( ( ) => ( view as any ) . container ) . toThrowErrorMatchingInlineSnapshot ( `
226
226
"'container' property has been renamed to 'UNSAFE_root'.
227
227
228
228
Consider using 'root' property which returns root host element."
229
229
` ) ;
230
- expect ( ( ) => screen . container ) . toThrowErrorMatchingInlineSnapshot ( `
230
+ expect ( ( ) => ( screen as any ) . container ) . toThrowErrorMatchingInlineSnapshot ( `
231
231
"'container' property has been renamed to 'UNSAFE_root'.
232
232
233
233
Consider using 'root' property which returns root host element."
@@ -238,3 +238,10 @@ test('RenderAPI type', () => {
238
238
render ( < Banana /> ) as RenderAPI ;
239
239
expect ( true ) . toBeTruthy ( ) ;
240
240
} ) ;
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', () => {
56
56
expect ( ( ) => screen . UNSAFE_root ) . toThrow (
57
57
'`render` method has not been called'
58
58
) ;
59
- expect ( ( ) => screen . container ) . toThrow ( '`render` method has not been called' ) ;
60
59
expect ( ( ) => screen . debug ( ) ) . toThrow ( '`render` method has not been called' ) ;
61
60
expect ( ( ) => screen . debug . shallow ( ) ) . toThrow (
62
61
'`render` method has not been called'
Original file line number Diff line number Diff line change @@ -111,13 +111,19 @@ function buildRenderResult(
111
111
return getHostChildren ( instance ) [ 0 ] ;
112
112
} ,
113
113
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 ( ) {
115
121
throw new Error (
116
122
"'container' property has been renamed to 'UNSAFE_root'.\n\n" +
117
123
"Consider using 'root' property which returns root host element."
118
124
) ;
119
125
} ,
120
- } ;
126
+ } ) ;
121
127
122
128
setRenderResult ( result ) ;
123
129
return result ;
Original file line number Diff line number Diff line change @@ -13,9 +13,6 @@ const notImplementedDebug = () => {
13
13
notImplementedDebug . shallow = notImplemented ;
14
14
15
15
const defaultScreen : RenderResult = {
16
- get container ( ) : ReactTestInstance {
17
- throw new Error ( SCREEN_ERROR ) ;
18
- } ,
19
16
get root ( ) : ReactTestInstance {
20
17
throw new Error ( SCREEN_ERROR ) ;
21
18
} ,
You can’t perform that action at this time.
0 commit comments