@@ -17,7 +17,7 @@ const PLACEHOLDER_CHEF = 'Who inspected freshness?';
17
17
const INPUT_FRESHNESS = 'Custom Freshie' ;
18
18
const INPUT_CHEF = 'I inspected freshie' ;
19
19
20
- class Button extends React . Component < any > {
20
+ class MyButton extends React . Component < any > {
21
21
render ( ) {
22
22
return (
23
23
< TouchableOpacity onPress = { this . props . onPress } >
@@ -68,9 +68,9 @@ class Banana extends React.Component<any, any> {
68
68
placeholder = { PLACEHOLDER_CHEF }
69
69
value = { INPUT_CHEF }
70
70
/>
71
- < Button onPress = { this . changeFresh } type = "primary" >
71
+ < MyButton onPress = { this . changeFresh } type = "primary" >
72
72
Change freshness!
73
- </ Button >
73
+ </ MyButton >
74
74
< Text testID = "duplicateText" > First Text</ Text >
75
75
< Text testID = "duplicateText" > Second Text</ Text >
76
76
< Text > { test } </ Text >
@@ -109,51 +109,18 @@ test('getAllByTestId, queryAllByTestId', () => {
109
109
expect ( queryAllByTestId ( 'nonExistentTestId' ) ) . toHaveLength ( 0 ) ;
110
110
} ) ;
111
111
112
- test ( 'getByName, queryByName' , ( ) => {
113
- const { getByText, getByName, queryByName } = render ( < Banana /> ) ;
114
- const bananaFresh = getByText ( 'not fresh' ) ;
115
- const button = getByName ( 'Button' ) ;
116
-
117
- button . props . onPress ( ) ;
118
-
119
- expect ( bananaFresh . props . children ) . toBe ( 'fresh' ) ;
120
-
121
- const sameButton = getByName ( Button ) ;
122
- sameButton . props . onPress ( ) ;
123
-
124
- expect ( bananaFresh . props . children ) . toBe ( 'not fresh' ) ;
125
- expect ( ( ) => getByName ( 'InExistent' ) ) . toThrow ( 'No instances found' ) ;
126
- expect ( ( ) => getByName ( Text ) ) . toThrow ( 'Expected 1 but found 6' ) ;
127
-
128
- expect ( queryByName ( 'Button' ) ) . toBe ( button ) ;
129
- expect ( queryByName ( 'InExistent' ) ) . toBeNull ( ) ;
130
- } ) ;
131
-
132
- test ( 'getAllByName, queryAllByName' , ( ) => {
133
- const { getAllByName, queryAllByName } = render ( < Banana /> ) ;
134
- const [ text , status , button ] = getAllByName ( 'Text' ) ;
135
-
136
- expect ( text . props . children ) . toBe ( 'Is the banana fresh?' ) ;
137
- expect ( status . props . children ) . toBe ( 'not fresh' ) ;
138
- expect ( button . props . children ) . toBe ( 'Change freshness!' ) ;
139
- expect ( ( ) => getAllByName ( 'InExistent' ) ) . toThrow ( 'No instances found' ) ;
140
-
141
- expect ( queryAllByName ( 'Text' ) [ 1 ] ) . toBe ( status ) ;
142
- expect ( queryAllByName ( 'InExistent' ) ) . toHaveLength ( 0 ) ;
143
- } ) ;
144
-
145
- test ( 'getAllByType, queryAllByType' , ( ) => {
146
- const { getAllByType, queryAllByType } = render ( < Banana /> ) ;
147
- const [ text , status , button ] = getAllByType ( Text ) ;
112
+ test ( 'UNSAFE_getAllByType, UNSAFE_queryAllByType' , ( ) => {
113
+ const { UNSAFE_getAllByType, UNSAFE_queryAllByType } = render ( < Banana /> ) ;
114
+ const [ text , status , button ] = UNSAFE_getAllByType ( Text ) ;
148
115
const InExistent = ( ) => null ;
149
116
150
117
expect ( text . props . children ) . toBe ( 'Is the banana fresh?' ) ;
151
118
expect ( status . props . children ) . toBe ( 'not fresh' ) ;
152
119
expect ( button . props . children ) . toBe ( 'Change freshness!' ) ;
153
- expect ( ( ) => getAllByType ( InExistent ) ) . toThrow ( 'No instances found' ) ;
120
+ expect ( ( ) => UNSAFE_getAllByType ( InExistent ) ) . toThrow ( 'No instances found' ) ;
154
121
155
- expect ( queryAllByType ( Text ) [ 1 ] ) . toBe ( status ) ;
156
- expect ( queryAllByType ( InExistent ) ) . toHaveLength ( 0 ) ;
122
+ expect ( UNSAFE_queryAllByType ( Text ) [ 1 ] ) . toBe ( status ) ;
123
+ expect ( UNSAFE_queryAllByType ( InExistent ) ) . toHaveLength ( 0 ) ;
157
124
} ) ;
158
125
159
126
test ( 'getByText, queryByText' , ( ) => {
@@ -267,38 +234,37 @@ test('getAllByDisplayValue, queryAllByDisplayValue', () => {
267
234
expect ( queryAllByDisplayValue ( 'no value' ) ) . toHaveLength ( 0 ) ;
268
235
} ) ;
269
236
270
- test ( 'getByProps, queryByProps ' , ( ) => {
271
- const { getByProps , queryByProps } = render ( < Banana /> ) ;
272
- const primaryType = getByProps ( { type : 'primary' } ) ;
237
+ test ( 'UNSAFE_getByProps, UNSAFE_queryByProps ' , ( ) => {
238
+ const { UNSAFE_getByProps , UNSAFE_queryByProps } = render ( < Banana /> ) ;
239
+ const primaryType = UNSAFE_getByProps ( { type : 'primary' } ) ;
273
240
274
241
expect ( primaryType . props . children ) . toBe ( 'Change freshness!' ) ;
275
- expect ( ( ) => getByProps ( { type : 'inexistent' } ) ) . toThrow (
242
+ expect ( ( ) => UNSAFE_getByProps ( { type : 'inexistent' } ) ) . toThrow (
276
243
'No instances found'
277
244
) ;
278
245
279
- expect ( queryByProps ( { type : 'primary' } ) ) . toBe ( primaryType ) ;
280
- expect ( queryByProps ( { type : 'inexistent' } ) ) . toBeNull ( ) ;
246
+ expect ( UNSAFE_queryByProps ( { type : 'primary' } ) ) . toBe ( primaryType ) ;
247
+ expect ( UNSAFE_queryByProps ( { type : 'inexistent' } ) ) . toBeNull ( ) ;
281
248
} ) ;
282
249
283
- test ( 'getAllByProp, queryAllByProps ' , ( ) => {
284
- const { getAllByProps , queryAllByProps } = render ( < Banana /> ) ;
285
- const primaryTypes = getAllByProps ( { type : 'primary' } ) ;
250
+ test ( 'UNSAFE_getAllByProp, UNSAFE_queryAllByProps ' , ( ) => {
251
+ const { UNSAFE_getAllByProps , UNSAFE_queryAllByProps } = render ( < Banana /> ) ;
252
+ const primaryTypes = UNSAFE_getAllByProps ( { type : 'primary' } ) ;
286
253
287
254
expect ( primaryTypes ) . toHaveLength ( 1 ) ;
288
- expect ( ( ) => getAllByProps ( { type : 'inexistent' } ) ) . toThrow (
255
+ expect ( ( ) => UNSAFE_getAllByProps ( { type : 'inexistent' } ) ) . toThrow (
289
256
'No instances found'
290
257
) ;
291
258
292
- expect ( queryAllByProps ( { type : 'primary' } ) ) . toEqual ( primaryTypes ) ;
293
- expect ( queryAllByProps ( { type : 'inexistent' } ) ) . toHaveLength ( 0 ) ;
259
+ expect ( UNSAFE_queryAllByProps ( { type : 'primary' } ) ) . toEqual ( primaryTypes ) ;
260
+ expect ( UNSAFE_queryAllByProps ( { type : 'inexistent' } ) ) . toHaveLength ( 0 ) ;
294
261
} ) ;
295
262
296
263
test ( 'update' , ( ) => {
297
264
const fn = jest . fn ( ) ;
298
- const { getByName, update, rerender } = render ( < Banana onUpdate = { fn } /> ) ;
299
- const button = getByName ( 'Button' ) ;
265
+ const { getByText, update, rerender } = render ( < Banana onUpdate = { fn } /> ) ;
300
266
301
- button . props . onPress ( ) ;
267
+ fireEvent . press ( getByText ( 'Change freshness!' ) ) ;
302
268
303
269
update ( < Banana onUpdate = { fn } /> ) ;
304
270
rerender ( < Banana onUpdate = { fn } /> ) ;
@@ -314,7 +280,7 @@ test('unmount', () => {
314
280
} ) ;
315
281
316
282
test ( 'toJSON' , ( ) => {
317
- const { toJSON } = render ( < Button > press me</ Button > ) ;
283
+ const { toJSON } = render ( < MyButton > press me</ MyButton > ) ;
318
284
319
285
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
320
286
} ) ;
@@ -345,9 +311,9 @@ test('debug', () => {
345
311
test ( 'debug changing component' , ( ) => {
346
312
jest . spyOn ( console , 'log' ) . mockImplementation ( ( x ) => x ) ;
347
313
348
- const { getByProps , debug } = render ( < Banana /> ) ;
314
+ const { UNSAFE_getByProps , debug } = render ( < Banana /> ) ;
349
315
350
- fireEvent . press ( getByProps ( { type : 'primary' } ) ) ;
316
+ fireEvent . press ( UNSAFE_getByProps ( { type : 'primary' } ) ) ;
351
317
352
318
debug ( ) ;
353
319
0 commit comments