@@ -37,6 +37,7 @@ describe('ReactTestRendererTraversal', () => {
37
37
< View void = "void" />
38
38
< View void = "void" />
39
39
</ ExampleNull >
40
+ < ExampleForwardRef qux = "qux" />
40
41
</ View >
41
42
</ View >
42
43
) ;
@@ -48,13 +49,17 @@ describe('ReactTestRendererTraversal', () => {
48
49
const ExampleFn = props => < View baz = "baz" /> ;
49
50
const ExampleNull = props => null ;
50
51
52
+ const ExampleForwardRef = React . forwardRef ( ( props , ref ) => (
53
+ < View { ...props } ref = { ref } />
54
+ ) ) ;
55
+
51
56
it ( 'initializes' , ( ) => {
52
57
const render = ReactTestRenderer . create ( < Example /> ) ;
53
58
const hasFooProp = node => node . props . hasOwnProperty ( 'foo' ) ;
54
59
55
60
// assert .props, .type and .parent attributes
56
61
const foo = render . root . find ( hasFooProp ) ;
57
- expect ( foo . props . children ) . toHaveLength ( 7 ) ;
62
+ expect ( foo . props . children ) . toHaveLength ( 8 ) ;
58
63
expect ( foo . type ) . toBe ( View ) ;
59
64
expect ( render . root . parent ) . toBe ( null ) ;
60
65
expect ( foo . children [ 0 ] . parent ) . toBe ( foo ) ;
@@ -116,14 +121,16 @@ describe('ReactTestRendererTraversal', () => {
116
121
117
122
expect ( ( ) => render . root . findByType ( ExampleFn ) ) . not . toThrow ( ) ; // 1 match
118
123
expect ( ( ) => render . root . findByType ( View ) ) . not . toThrow ( ) ; // 1 match
124
+ expect ( ( ) => render . root . findByType ( ExampleForwardRef ) ) . not . toThrow ( ) ; // 1 match
119
125
// note: there are clearly multiple <View /> in general, but there
120
126
// is only one being rendered at root node level
121
127
expect ( ( ) => render . root . findByType ( ExampleNull ) ) . toThrow ( ) ; // 2 matches
122
128
123
129
expect ( render . root . findAllByType ( ExampleFn ) ) . toHaveLength ( 1 ) ;
124
130
expect ( render . root . findAllByType ( View , { deep : false } ) ) . toHaveLength ( 1 ) ;
125
- expect ( render . root . findAllByType ( View ) ) . toHaveLength ( 7 ) ;
131
+ expect ( render . root . findAllByType ( View ) ) . toHaveLength ( 8 ) ;
126
132
expect ( render . root . findAllByType ( ExampleNull ) ) . toHaveLength ( 2 ) ;
133
+ expect ( render . root . findAllByType ( ExampleForwardRef ) ) . toHaveLength ( 1 ) ;
127
134
128
135
const nulls = render . root . findAllByType ( ExampleNull ) ;
129
136
expect ( nulls [ 0 ] . findAllByType ( View ) ) . toHaveLength ( 0 ) ;
@@ -138,17 +145,21 @@ describe('ReactTestRendererTraversal', () => {
138
145
const foo = 'foo' ;
139
146
const bar = 'bar' ;
140
147
const baz = 'baz' ;
148
+ const qux = 'qux' ;
141
149
142
150
expect ( ( ) => render . root . findByProps ( { foo} ) ) . not . toThrow ( ) ; // 1 match
143
151
expect ( ( ) => render . root . findByProps ( { bar} ) ) . toThrow ( ) ; // >1 matches
144
152
expect ( ( ) => render . root . findByProps ( { baz} ) ) . toThrow ( ) ; // >1 matches
153
+ expect ( ( ) => render . root . findByProps ( { qux} ) ) . not . toThrow ( ) ; // 1 match
145
154
146
155
expect ( render . root . findAllByProps ( { foo} , { deep : false } ) ) . toHaveLength ( 1 ) ;
147
156
expect ( render . root . findAllByProps ( { bar} , { deep : false } ) ) . toHaveLength ( 5 ) ;
148
157
expect ( render . root . findAllByProps ( { baz} , { deep : false } ) ) . toHaveLength ( 2 ) ;
158
+ expect ( render . root . findAllByProps ( { qux} , { deep : false } ) ) . toHaveLength ( 1 ) ;
149
159
150
160
expect ( render . root . findAllByProps ( { foo} ) ) . toHaveLength ( 2 ) ;
151
161
expect ( render . root . findAllByProps ( { bar} ) ) . toHaveLength ( 9 ) ;
152
162
expect ( render . root . findAllByProps ( { baz} ) ) . toHaveLength ( 4 ) ;
163
+ expect ( render . root . findAllByProps ( { qux} ) ) . toHaveLength ( 3 ) ;
153
164
} ) ;
154
165
} ) ;
0 commit comments