Skip to content

Commit 579281f

Browse files
committed
readme update
1 parent b64c9cf commit 579281f

6 files changed

Lines changed: 124 additions & 186 deletions

File tree

README.md

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<img alt="banner" src="https://github.com/vanGalilea/react-native-testing/assets/25864161/fd4d5148-4c8d-4fbc-8ebf-367d72da4fcb">
33
</p>
44

5-
## No More Hacks and Headaches | Learn How to Test Your Components Before Your Users Will
5+
## No More Hacks and Headaches <> Learn How to Test Your Components Before Your Users Will
66

77
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=vanGalilea_react-native-testing&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=vanGalilea_react-native-testing)
88
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=vanGalilea_react-native-testing&metric=coverage)](https://sonarcloud.io/summary/new_code?id=vanGalilea_react-native-testing)
@@ -11,16 +11,17 @@
1111

1212
### Covered Examples 🎞
1313
- 👆 [Clicking buttons and asserting onPress' outcome](https://github.com/vanGalilea/react-native-testing/blob/main/apps/rn-cli-app/__tests__/Counter.test.tsx).
14-
- 📲 [Filling a simple login form and asserting successful submission](https://github.com/vanGalilea/react-native-testing/blob/master/__tests__/LoginSubmission.test.tsx).
15-
- 🎣 [Custom hook testing (number of alternatives)](https://github.com/vanGalilea/react-native-testing/blob/master/__tests__/CounterUsesCustomHook.test.tsx).
16-
- 📡 [Mocking fetch calls](https://github.com/vanGalilea/react-native-testing/blob/master/__tests__/LoginSubmission.test.tsx#L36).
17-
- 🧭 [Mocking navigation through screens](https://github.com/vanGalilea/react-native-testing/blob/master/__tests__/LoginSubmission.test.tsx#L13). ([react navigation v5](https://reactnavigation.org/))
18-
- 🔚 [E2E feel due to real navigation throughout screens](https://github.com/vanGalilea/react-native-testing/blob/master/__tests__/Home.test.tsx).
19-
- 📥 [Handling and mocking providers](https://github.com/vanGalilea/react-native-testing/blob/master/src/test/test-utils.tsx).
20-
- 📹 [Mocking external lib.'s components](https://github.com/vanGalilea/react-native-testing/blob/master/__tests__/Video.test.tsx).
21-
- 🎭 [Mocking and interacting with RN's Modal component](https://github.com/vanGalilea/react-native-testing/blob/master/__tests__/Modal.test.tsx).
22-
- 🧾 [Handling with a screen with RN's FlatList component](https://github.com/vanGalilea/react-native-testing/blob/master/__tests__/FlatList.test.tsx).
23-
- 📡 [Using MSW to mock api calls and handling loading/errors](https://github.com/vanGalilea/react-native-testing/blob/master/__tests__/ListWithFetch.test.tsx).
14+
- 📲 [Filling a simple login form and asserting successful submission](https://github.com/vanGalilea/react-native-testing/blob/main/apps/rn-cli-app/__tests__/LoginSubmission.test.tsx).
15+
- 🎣 [Custom hook testing (number of alternatives)](https://github.com/vanGalilea/react-native-testing/blob/main/apps/rn-cli-app/__tests__/CounterUsesCustomHook.test.tsx).
16+
- 📡 [Mocking fetch calls](https://github.com/vanGalilea/react-native-testing/blob/main/apps/rn-cli-app/__tests__/LoginSubmission.test.tsx#L36).
17+
- 🧭 [Navigating through screens with React Navigation](https://github.com/vanGalilea/react-native-testing/blob/main/apps/rn-cli-app/__tests__/LoginSubmission.test.tsx#L13).
18+
- 🚟 [Navigating through screens with Expo Router](https://github.com/vanGalilea/react-native-testing/blob/main/apps/rn-expo-app/__tests__/app/index.test.tsx).
19+
- 🔚 [E2E feel due to real navigation throughout screens](https://github.com/vanGalilea/react-native-testing/blob/main/apps/rn-cli-app/__tests__/Home.test.tsx).
20+
- 📥 [Handling and mocking providers](https://github.com/vanGalilea/react-native-testing/blob/main/apps/rn-cli-app/src/test/test-utils.tsx).
21+
- 📹 [Mocking external lib.'s components](https://github.com/vanGalilea/react-native-testing/blob/main/apps/rn-cli-app/__tests__/Video.test.tsx).
22+
- 🎭 [Mocking and interacting with RN's Modal component](https://github.com/vanGalilea/react-native-testing/blob/main/apps/rn-cli-app/__tests__/Modal.test.tsx).
23+
- 🧾 [Handling with a screen with RN's FlatList component](https://github.com/vanGalilea/react-native-testing/blob/main/apps/rn-cli-app/__tests__/FlatList.test.tsx).
24+
- 📡 [Using MSW to mock api calls and handling loading/errors](https://github.com/vanGalilea/react-native-testing/blob/main/apps/rn-cli-app/__tests__/ListWithFetch.test.tsx).
2425

2526
### Tools in use 🛠️
2627
- [Jest](https://jestjs.io/)
@@ -31,25 +32,39 @@
3132
- [RN- Setting up the development environment](https://reactnative.dev/docs/environment-setup)
3233
- [Installing Maestro](https://maestro.mobile.dev/getting-started/installing-maestro)
3334

34-
### How to run the tests 🏃‍♀️
35-
- Clone the repo
35+
## Getting Started 🚀
36+
- Clone the repo ` git clone git@github.com:vanGalilea/react-native-testing.git`
3637
- Run `yarn` to install dependencies
38+
- Explore RN CLI app and/or Expo app's tests and source code that are relevant to your use case.
39+
40+
41+
## RN CLI application
42+
### How to run the tests 🏃‍♀️
43+
- Run `cd apps/rn-cli-app` to navigate to the app folder
3744
- Run `yarn test:unit` to run the unit tests
3845
- Run `yarn test:unit:dev` to run the unit tests in dev/watch mode
3946
- Run `yarn test:unit:coverage` to run the tests and generate a coverage report
47+
48+
Make sure you have built and run the app in dev mode before running the e2e tests.
4049
- Run `yarn test:e2e` to run the e2e tests
4150
- Run `yarn test:e2e:dev` to run the e2e tests in dev/watch mode
4251
- Run `yarn test:e2e:record` to run the e2e tests and record a video of the tests
4352

4453
### How to run the app 📱
45-
- Clone the repo
46-
- Run `yarn` to install dependencies
54+
- Run `cd apps/rn-cli-app` to navigate to the app folder
4755
- Run `npx pod-install` to install iOS dependencies
4856
- Run `yarn start` to start the metro bundler
4957
- Click `i` to run the app on iOS simulator or `a` to run it on Android emulator
5058

51-
### Ideas and future improvements 🚀
52-
- ⚛️ Add tests for react native web project
59+
## Expo application
60+
### How to run the tests 🏃‍♀️
61+
- Run `cd apps/rn-expo-app` to navigate to the app folder
62+
- Run `yarn test:unit` to run the unit tests
63+
64+
### How to run the app 📱
65+
- Run `cd apps/rn-expo-app` to navigate to the app folder
66+
- Run `yarn start` to start the metro bundler
67+
- Click `i` to run the app on iOS simulator or `a` to run it on Android emulator
5368

5469
### Inspiration, resources and further reading 📚
5570
- 📑 A blog by [Steve Galili]([url](https://github.com/vanGalilea)) on ["Where and How to Start Testing Your React Native App"](https://medium.com/@stevegalili/where-and-how-to-start-testing-your-react-native-app-%EF%B8%8F-and-how-to-keep-on-testin-ec3464fb9b41)
@@ -61,7 +76,6 @@ For more info check [Epic React](https://epicreact.dev/).
6176
- 🗺 [React Navigation](https://reactnavigation.org/)
6277
- 🛰 [MSW](https://mswjs.io/)
6378

64-
### Impression of the the project 📸
65-
79+
### Impression of the project 📸
6680
https://github.com/vanGalilea/react-native-testing/assets/25864161/cdb6cdc7-7b28-4ecd-819f-52dd3c3d76c8
6781

apps/rn-cli-app/App.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import {NavigationContainer} from '@react-navigation/native';
2+
import {NavigationContainer, useNavigation} from '@react-navigation/native';
33
import {
44
createStackNavigator,
55
StackNavigationProp,
@@ -13,7 +13,7 @@ import {ThemeProvider} from './src/utils/theme';
1313
import ListWithFetch from './src/components/ListWithFetch';
1414
import LoginSubmission from './src/components/LoginSubmission';
1515
import Counter from './src/components/Counter';
16-
import {Alert} from 'react-native';
16+
import {Alert, Pressable, Text} from 'react-native';
1717

1818
export type RootStackParamList = {
1919
Home: undefined;
@@ -53,7 +53,7 @@ export default () => {
5353
<Stack.Navigator
5454
initialRouteName="Home"
5555
screenOptions={{
56-
headerBackTestID: 'go-back-home-button',
56+
headerLeft: HeaderLeft,
5757
}}>
5858
<Stack.Screen name={SCREENS.HOME} component={Home} />
5959
<Stack.Screen name={SCREENS.LOGIN} component={LoginSubmission} />
@@ -75,3 +75,18 @@ export default () => {
7575
</>
7676
);
7777
};
78+
79+
const HeaderLeft = () => {
80+
const navigation = useNavigation();
81+
if (!navigation.canGoBack()) {
82+
return null;
83+
}
84+
85+
return (
86+
<Pressable
87+
testID={'go-back-home-button'}
88+
onPress={() => navigation.goBack()}>
89+
<Text style={{fontSize: 24}}></Text>
90+
</Pressable>
91+
);
92+
};

apps/rn-cli-app/ios/Podfile.lock

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,8 +1126,6 @@ PODS:
11261126
- React-Core
11271127
- RNCMaskedView (0.1.11):
11281128
- React
1129-
- RNFlashList (1.6.3):
1130-
- React-Core
11311129
- RNGestureHandler (2.14.1):
11321130
- glog
11331131
- RCT-Folly (= 2022.05.16.00)
@@ -1216,7 +1214,6 @@ DEPENDENCIES:
12161214
- ReactCommon/turbomodule/core (from `../../../node_modules/react-native/ReactCommon`)
12171215
- "RNCAsyncStorage (from `../../../node_modules/@react-native-community/async-storage`)"
12181216
- "RNCMaskedView (from `../../../node_modules/@react-native-community/masked-view`)"
1219-
- "RNFlashList (from `../../../node_modules/@shopify/flash-list`)"
12201217
- RNGestureHandler (from `../../../node_modules/react-native-gesture-handler`)
12211218
- RNScreens (from `../../../node_modules/react-native-screens`)
12221219
- Yoga (from `../../../node_modules/react-native/ReactCommon/yoga`)
@@ -1343,8 +1340,6 @@ EXTERNAL SOURCES:
13431340
:path: "../../../node_modules/@react-native-community/async-storage"
13441341
RNCMaskedView:
13451342
:path: "../../../node_modules/@react-native-community/masked-view"
1346-
RNFlashList:
1347-
:path: "../../../node_modules/@shopify/flash-list"
13481343
RNGestureHandler:
13491344
:path: "../../../node_modules/react-native-gesture-handler"
13501345
RNScreens:
@@ -1418,7 +1413,6 @@ SPEC CHECKSUMS:
14181413
ReactCommon: ddb128564dcbfa0287d3d1a2d10f8c7457c971f6
14191414
RNCAsyncStorage: b03032fdbdb725bea0bd9e5ec5a7272865ae7398
14201415
RNCMaskedView: 0e1bc4bfa8365eba5fbbb71e07fbdc0555249489
1421-
RNFlashList: 4b4b6b093afc0df60ae08f9cbf6ccd4c836c667a
14221416
RNGestureHandler: 25b969a1ffc806b9f9ad2e170d4a3b049c6af85e
14231417
RNScreens: b582cb834dc4133307562e930e8fa914b8c04ef2
14241418
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17

apps/rn-cli-app/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"test:unit": "jest",
1111
"test:unit:dev": "jest --watch",
1212
"test:unit:coverage": "jest --coverage",
13-
"test:e2e": "maestro test e2e/flow.yaml",
14-
"test:e2e:dev": "maestro test -c e2e/flow.yaml",
15-
"test:e2e:record": "maestro record e2e/flow.yaml"
13+
"test:e2e": "maestro test .maestro/flow.yaml",
14+
"test:e2e:dev": "maestro test -c .maestro/flow.yaml",
15+
"test:e2e:record": "maestro record .maestro/flow.yaml"
1616
},
1717
"dependencies": {
1818
"@react-native-community/async-storage": "^1.12.1",

apps/rn-expo-app/.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,3 @@ yarn-error.*
3434
# typescript
3535
*.tsbuildinfo
3636

37-
# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
38-
# The following patterns were generated by expo-cli
39-
40-
expo-env.d.ts
41-
# @end expo-cli

0 commit comments

Comments
 (0)