No More Hacks and Headaches | Learn How to Test Your Components Before Your Users Will
๐
Covered Examples ๐ Clicking buttons and asserting onPress' outcome.๐ฒ Filling a simple login form and asserting successful submission.๐ฃ Custom hook testing (number of alternatives).๐ก Mocking fetch calls.๐งญ Mocking navigation through screens. (react navigation v5)๐ E2E feel due to real navigation throughout screens.๐ฅ Handling and mocking providers.๐น Mocking external lib.'s components.๐ญ Mocking and interacting with RN's Modal component.๐งพ Handling with a screen with RN's FlatList component.๐ก Using MSW to mock api calls and handling loading/errors.
๐ ๏ธ
Tools in use
๐โโ๏ธ
How to run the tests - Clone the repo
- Run
yarn
to install dependencies - Run
yarn test
to run the tests - Run
yarn test:coverage
to run the tests and generate a coverage report
๐ฑ
How to run the app - Clone the repo
- Run
yarn
to install dependencies - Run
npx pod-install
to install iOS dependencies - Run
yarn start
to start the metro bundler - Click
i
to run the app on iOS simulator ora
to run it on Android emulator
๐
Ideas and future improvements ๐ฑ Add E2E tests with Maestroโ๏ธ Add tests for react native web project
๐
Inspiration, resources and further reading ๐ A blog by Steve Galili on "Where and How to Start Testing Your React Native App"๐ Inspired by Kent C. Dodds' workshop Test React Components with Jest and React Testing Library. For more info check Epic React.๐ React Native Testing Library๐งโ๐ฌ๏ธ Jest- ๏ธ
โ๏ธ React Native ๐บ React Navigation๐ฐ MSW