11const React = require ( 'react' ) ;
22require ( 'react-native' ) ;
3- const renderer = require ( 'react-test-renderer ' ) ;
3+ const { render , act } = require ( '@testing-library/ react-native ' ) ;
44const { Provider } = require ( 'react-redux' ) ;
55const { Navigation } = require ( '../../lib/src/index' ) ;
66
@@ -30,8 +30,8 @@ describe('redux support', () => {
3030 store . reduxStore
3131 ) ;
3232
33- const tree = renderer . create ( < HOC /> ) ;
34- expect ( tree . toJSON ( ) . children ) . toEqual ( [ 'no name' ] ) ;
33+ const { getByText } = render ( < HOC /> ) ;
34+ expect ( getByText ( 'no name' ) ) . toBeTruthy ( ) ;
3535 } ) ;
3636
3737 it ( 'passes props into wrapped components' , ( ) => {
@@ -50,46 +50,49 @@ describe('redux support', () => {
5050 < HOC { ...props } />
5151 ) ) ( ) ;
5252
53- const tree = renderer . create (
53+ const { getByText } = render (
5454 < CompFromNavigation componentId = "componentId" renderCountIncrement = { renderCountIncrement } />
5555 ) ;
56- expect ( tree . toJSON ( ) . children ) . toEqual ( [ 'no name' ] ) ;
56+ expect ( getByText ( 'no name' ) ) . toBeTruthy ( ) ;
5757 expect ( renderCountIncrement ) . toHaveBeenCalledTimes ( 1 ) ;
5858 } ) ;
5959
6060 it ( 'rerenders as a result of an underlying state change (by selector)' , ( ) => {
6161 const renderCountIncrement = jest . fn ( ) ;
62- const tree = renderer . create (
62+ const { getByText , rerender } = render (
6363 < Provider store = { store . reduxStore } >
6464 < MyConnectedComponent renderCountIncrement = { renderCountIncrement } />
6565 </ Provider >
6666 ) ;
6767
68- expect ( tree . toJSON ( ) . children ) . toEqual ( [ 'no name' ] ) ;
68+ expect ( getByText ( 'no name' ) ) . toBeTruthy ( ) ;
6969 expect ( renderCountIncrement ) . toHaveBeenCalledTimes ( 1 ) ;
7070
71- store . reduxStore . dispatch ( { type : 'redux.MyStore.setName' , name : 'Bob' } ) ;
71+ act ( ( ) => {
72+ store . reduxStore . dispatch ( { type : 'redux.MyStore.setName' , name : 'Bob' } ) ;
73+ } ) ;
7274 expect ( store . selectors . getName ( store . reduxStore . getState ( ) ) ) . toEqual ( 'Bob' ) ;
73- expect ( tree . toJSON ( ) . children ) . toEqual ( [ 'Bob' ] ) ;
74-
75+ expect ( getByText ( 'Bob' ) ) . toBeTruthy ( ) ;
7576 expect ( renderCountIncrement ) . toHaveBeenCalledTimes ( 2 ) ;
7677 } ) ;
7778
7879 it ( 'rerenders as a result of an underlying state change with a new key' , ( ) => {
7980 const renderCountIncrement = jest . fn ( ) ;
80- const tree = renderer . create (
81+ const { queryByText , rerender } = render (
8182 < Provider store = { store . reduxStore } >
8283 < MyConnectedComponent printAge = { true } renderCountIncrement = { renderCountIncrement } />
8384 </ Provider >
8485 ) ;
8586
86- expect ( tree . toJSON ( ) . children ) . toEqual ( null ) ;
87+ // Initially should show nothing (null children means no text)
88+ expect ( queryByText ( '30' ) ) . toBeNull ( ) ;
8789 expect ( renderCountIncrement ) . toHaveBeenCalledTimes ( 1 ) ;
8890
89- store . reduxStore . dispatch ( { type : 'redux.MyStore.setAge' , age : 30 } ) ;
91+ act ( ( ) => {
92+ store . reduxStore . dispatch ( { type : 'redux.MyStore.setAge' , age : 30 } ) ;
93+ } ) ;
9094 expect ( store . selectors . getAge ( store . reduxStore . getState ( ) ) ) . toEqual ( 30 ) ;
91- expect ( tree . toJSON ( ) . children ) . toEqual ( [ '30' ] ) ;
92-
95+ expect ( queryByText ( '30' ) ) . toBeTruthy ( ) ;
9396 expect ( renderCountIncrement ) . toHaveBeenCalledTimes ( 2 ) ;
9497 } ) ;
9598} ) ;
0 commit comments