diff --git a/examples/reactnavigation/jest-setup.js b/examples/reactnavigation/jest-setup.js index baa4ed853..66e9c6598 100644 --- a/examples/reactnavigation/jest-setup.js +++ b/examples/reactnavigation/jest-setup.js @@ -1,14 +1,2 @@ -import 'react-native-gesture-handler/jestSetup'; - -jest.mock('react-native-reanimated', () => { - const Reanimated = require('react-native-reanimated/mock'); - - // The mock for `call` immediately calls the callback which is incorrect - // So we override it with a no-op - Reanimated.default.call = () => {}; - - return Reanimated; -}); - // Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper'); diff --git a/examples/reactnavigation/jest.config.js b/examples/reactnavigation/jest.config.js index ec9c1a2a0..08aae2876 100644 --- a/examples/reactnavigation/jest.config.js +++ b/examples/reactnavigation/jest.config.js @@ -1,7 +1,7 @@ module.exports = { preset: 'react-native', - setupFiles: ['./jest-setup.js'], + setupFilesAfterEnv: ['./jest-setup.js'], transformIgnorePatterns: [ - 'node_modules/(?!(jest-)?react-native|@react-native-community|@react-navigation)', + 'node_modules/(?!(jest-)?react-native|@react-native|@react-native-community|@react-navigation)', ], }; diff --git a/examples/reactnavigation/package.json b/examples/reactnavigation/package.json index 510afa104..9db6de384 100644 --- a/examples/reactnavigation/package.json +++ b/examples/reactnavigation/package.json @@ -7,25 +7,20 @@ "test": "jest" }, "dependencies": { - "@react-native-community/masked-view": "^0.1.9", - "@react-navigation/drawer": "^5.11.4", - "@react-navigation/native": "^5.1.6", - "@react-navigation/stack": "^5.2.13", - "prop-types": "^15.7.2", - "react": "^16.13.1", - "react-native": "^0.62.2", - "react-native-gesture-handler": "^1.6.1", - "react-native-reanimated": "^1.8.0", - "react-native-safe-area-context": "^0.7.3", - "react-native-screens": "^2.5.0" + "@react-navigation/native": "^6.0.11", + "@react-navigation/native-stack": "^6.7.0", + "@react-navigation/stack": "^6.2.2", + "react": "^18.0.0", + "react-native": "^0.69.2", + "react-native-safe-area-context": "^4.3.1", + "react-native-screens": "^3.15.0" }, "devDependencies": { "@babel/core": "^7.9.0", - "@babel/runtime": "^7.9.2", - "babel-jest": "^25.4.0", - "jest": "^25.4.0", - "metro-react-native-babel-preset": "^0.59.0", - "@testing-library/react-native": "^7.0.0-rc.0", - "react-test-renderer": "^16.13.1" + "@testing-library/react-native": "^11.0.0", + "babel-jest": "^28.0.0", + "jest": "^28.0.0", + "metro-react-native-babel-preset": "^0.70.0", + "react-test-renderer": "^18.0.0" } } diff --git a/examples/reactnavigation/src/App.js b/examples/reactnavigation/src/App.js index 8e8c32806..cb42b3adf 100644 --- a/examples/reactnavigation/src/App.js +++ b/examples/reactnavigation/src/App.js @@ -1,8 +1,6 @@ -import 'react-native-gesture-handler'; import React from 'react'; import { StatusBar, StyleSheet, View } from 'react-native'; import { NavigationContainer } from '@react-navigation/native'; - import AppNavigator from './AppNavigator'; export default function App() { diff --git a/examples/reactnavigation/src/AppNavigator.js b/examples/reactnavigation/src/AppNavigator.js index 0f9dcde6e..2f6aa4a03 100644 --- a/examples/reactnavigation/src/AppNavigator.js +++ b/examples/reactnavigation/src/AppNavigator.js @@ -1,18 +1,15 @@ import * as React from 'react'; -import { createStackNavigator } from '@react-navigation/stack'; - +import { createNativeStackNavigator } from '@react-navigation/native-stack'; import HomeScreen from './screens/HomeScreen'; import DetailsScreen from './screens/DetailsScreen'; -const { Screen, Navigator } = createStackNavigator(); +const Stack = createNativeStackNavigator(); export default function Navigation() { - const options = {}; - return ( - - - - + + + + ); } diff --git a/examples/reactnavigation/src/AppNavigator.test.js b/examples/reactnavigation/src/AppNavigator.test.js new file mode 100644 index 000000000..9482126bb --- /dev/null +++ b/examples/reactnavigation/src/AppNavigator.test.js @@ -0,0 +1,24 @@ +import * as React from 'react'; +import { screen, fireEvent } from '@testing-library/react-native'; +import { renderWithNavigation } from './test-utils'; +import AppNavigator from './AppNavigator'; + +test('page contains the header and 10 items', async () => { + renderWithNavigation(); + + const header = await screen.findByText('List of numbers from 1 to 20'); + expect(header).toBeTruthy(); + + const items = screen.getAllByText(/Item number/); + expect(items.length).toBe(10); +}); + +test('clicking on one item takes you to the details screen', async () => { + renderWithNavigation(); + + const toClick = await screen.findByText('Item number 5'); + fireEvent(toClick, 'press'); + + expect(screen.getByText('Showing details for 5')).toBeTruthy(); + expect(screen.getByText('the number you have chosen is 5')).toBeTruthy(); +}); diff --git a/examples/reactnavigation/src/DrawerApp.js b/examples/reactnavigation/src/DrawerApp.js deleted file mode 100644 index caecc47a5..000000000 --- a/examples/reactnavigation/src/DrawerApp.js +++ /dev/null @@ -1,13 +0,0 @@ -import 'react-native-gesture-handler'; -import React from 'react'; -import { NavigationContainer } from '@react-navigation/native'; - -import DrawerAppNavigator from './DrawerAppNavigator'; - -export default function DrawerApp() { - return ( - - - - ); -} diff --git a/examples/reactnavigation/src/DrawerAppNavigator.js b/examples/reactnavigation/src/DrawerAppNavigator.js deleted file mode 100644 index 1a57f0ba8..000000000 --- a/examples/reactnavigation/src/DrawerAppNavigator.js +++ /dev/null @@ -1,35 +0,0 @@ -import React from 'react'; -import {createDrawerNavigator} from '@react-navigation/drawer'; -import {View, Button, Text} from 'react-native'; - -const { Screen, Navigator } = createDrawerNavigator(); - -function HomeScreen({ navigation }) { - return ( - - Welcome! -