1+ import 'jest-native/extend-expect' ;
12import React from 'react' ;
23import { Button , Text , View } from 'react-native' ;
34import { createStackNavigator , createAppContainer , withNavigation } from 'react-navigation' ;
45
5- import { render , fireEvent } from '../../src ' ;
6+ import { render , fireEvent } from 'native-testing-library ' ;
67
78jest . mock ( 'NativeAnimatedHelper' ) . mock ( 'react-native-gesture-handler' , ( ) => {
8- const View = require ( 'react-native/Libraries/Components/View/View' ) ;
9+ const View = require ( 'react-native' ) . View ;
910 return {
1011 State : { } ,
1112 PanGestureHandler : View ,
@@ -14,6 +15,7 @@ jest.mock('NativeAnimatedHelper').mock('react-native-gesture-handler', () => {
1415 } ;
1516} ) ;
1617
18+ const originalConsoleWarn = console . warn ;
1719console . warn = arg => {
1820 const warnings = [
1921 'Calling .measureInWindow()' ,
@@ -25,21 +27,23 @@ console.warn = arg => {
2527
2628 const finalArgs = warnings . reduce ( ( acc , curr ) => ( arg . includes ( curr ) ? [ ...acc , arg ] : acc ) , [ ] ) ;
2729
28- if ( ! finalArgs . length ) {
29- console . warn ( arg ) ;
30+ if ( finalArgs . length ) {
31+ return ;
3032 }
33+
34+ originalConsoleWarn ( message ) ;
3135} ;
3236
3337const Home = ( { navigation } ) => (
3438 < View >
3539 < Text testID = "title" > Home page</ Text >
36- < Button title = "About page " onPress = { ( ) => navigation . navigate ( 'About' ) } />
40+ < Button title = "Go to about " onPress = { ( ) => navigation . navigate ( 'About' ) } />
3741 </ View >
3842) ;
3943const About = ( { navigation } ) => (
4044 < View >
4145 < Text testID = "title" > About page</ Text >
42- < Button title = "About page " onPress = { ( ) => navigation . navigate ( 'Home' ) } />
46+ < Button title = "Go to home " onPress = { ( ) => navigation . navigate ( 'Home' ) } />
4347 </ View >
4448) ;
4549const Location = ( ) => (
@@ -71,15 +75,18 @@ function renderWithNavigation({ screens = {}, navigatorConfig = {} } = {}) {
7175
7276test ( 'full app rendering/navigating' , async ( ) => {
7377 const { findByText, getByTestId, getByText } = renderWithNavigation ( ) ;
74- expect ( getByTestId ( 'title' ) . props . children ) . toMatch ( 'Home page' ) ;
75- fireEvent . press ( getByText ( / A b o u t p a g e / i) ) ;
76- await expect ( findByText ( 'About page' ) ) . toBeTruthy ( ) ;
78+
79+ expect ( getByTestId ( 'title' ) ) . toHaveTextContent ( 'Home page' ) ;
80+ fireEvent . press ( getByText ( / G o t o a b o u t / i) ) ;
81+
82+ const result = await findByText ( 'About page' ) ;
83+ expect ( result ) . toHaveTextContent ( 'About page' ) ;
7784} ) ;
7885
7986test ( 'rendering a component that uses withNavigation' , ( ) => {
8087 const initialRouteName = 'Location' ;
8188 const { getByTestId } = renderWithNavigation ( {
8289 navigatorConfig : { initialRouteName } ,
8390 } ) ;
84- expect ( getByTestId ( 'location-display' ) . props . children ) . toBe ( initialRouteName ) ;
91+ expect ( getByTestId ( 'location-display' ) ) . toHaveTextContent ( initialRouteName ) ;
8592} ) ;
0 commit comments