@@ -17,7 +17,7 @@ const PLACEHOLDER_CHEF = 'Who inspected freshness?';
1717const INPUT_FRESHNESS = 'Custom Freshie' ;
1818const INPUT_CHEF = 'I inspected freshie' ;
1919
20- class Button extends React . Component < any > {
20+ class MyButton extends React . Component < any > {
2121 render ( ) {
2222 return (
2323 < TouchableOpacity onPress = { this . props . onPress } >
@@ -68,9 +68,9 @@ class Banana extends React.Component<any, any> {
6868 placeholder = { PLACEHOLDER_CHEF }
6969 value = { INPUT_CHEF }
7070 />
71- < Button onPress = { this . changeFresh } type = "primary" >
71+ < MyButton onPress = { this . changeFresh } type = "primary" >
7272 Change freshness!
73- </ Button >
73+ </ MyButton >
7474 < Text testID = "duplicateText" > First Text</ Text >
7575 < Text testID = "duplicateText" > Second Text</ Text >
7676 < Text > { test } </ Text >
@@ -109,51 +109,18 @@ test('getAllByTestId, queryAllByTestId', () => {
109109 expect ( queryAllByTestId ( 'nonExistentTestId' ) ) . toHaveLength ( 0 ) ;
110110} ) ;
111111
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 ) ;
148115 const InExistent = ( ) => null ;
149116
150117 expect ( text . props . children ) . toBe ( 'Is the banana fresh?' ) ;
151118 expect ( status . props . children ) . toBe ( 'not fresh' ) ;
152119 expect ( button . props . children ) . toBe ( 'Change freshness!' ) ;
153- expect ( ( ) => getAllByType ( InExistent ) ) . toThrow ( 'No instances found' ) ;
120+ expect ( ( ) => UNSAFE_getAllByType ( InExistent ) ) . toThrow ( 'No instances found' ) ;
154121
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 ) ;
157124} ) ;
158125
159126test ( 'getByText, queryByText' , ( ) => {
@@ -267,38 +234,37 @@ test('getAllByDisplayValue, queryAllByDisplayValue', () => {
267234 expect ( queryAllByDisplayValue ( 'no value' ) ) . toHaveLength ( 0 ) ;
268235} ) ;
269236
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' } ) ;
273240
274241 expect ( primaryType . props . children ) . toBe ( 'Change freshness!' ) ;
275- expect ( ( ) => getByProps ( { type : 'inexistent' } ) ) . toThrow (
242+ expect ( ( ) => UNSAFE_getByProps ( { type : 'inexistent' } ) ) . toThrow (
276243 'No instances found'
277244 ) ;
278245
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 ( ) ;
281248} ) ;
282249
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' } ) ;
286253
287254 expect ( primaryTypes ) . toHaveLength ( 1 ) ;
288- expect ( ( ) => getAllByProps ( { type : 'inexistent' } ) ) . toThrow (
255+ expect ( ( ) => UNSAFE_getAllByProps ( { type : 'inexistent' } ) ) . toThrow (
289256 'No instances found'
290257 ) ;
291258
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 ) ;
294261} ) ;
295262
296263test ( 'update' , ( ) => {
297264 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 } /> ) ;
300266
301- button . props . onPress ( ) ;
267+ fireEvent . press ( getByText ( 'Change freshness!' ) ) ;
302268
303269 update ( < Banana onUpdate = { fn } /> ) ;
304270 rerender ( < Banana onUpdate = { fn } /> ) ;
@@ -314,7 +280,7 @@ test('unmount', () => {
314280} ) ;
315281
316282test ( 'toJSON' , ( ) => {
317- const { toJSON } = render ( < Button > press me</ Button > ) ;
283+ const { toJSON } = render ( < MyButton > press me</ MyButton > ) ;
318284
319285 expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
320286} ) ;
@@ -345,9 +311,9 @@ test('debug', () => {
345311test ( 'debug changing component' , ( ) => {
346312 jest . spyOn ( console , 'log' ) . mockImplementation ( ( x ) => x ) ;
347313
348- const { getByProps , debug } = render ( < Banana /> ) ;
314+ const { UNSAFE_getByProps , debug } = render ( < Banana /> ) ;
349315
350- fireEvent . press ( getByProps ( { type : 'primary' } ) ) ;
316+ fireEvent . press ( UNSAFE_getByProps ( { type : 'primary' } ) ) ;
351317
352318 debug ( ) ;
353319
0 commit comments