This is a simple project template to demonstrate how to use MSW with React Native. It uses Jest and React Testing Library to test the application.
This application also has @tanstack/react-query to show how to use MSW with react-query for async state management and how I would typically test this in my application, including testing the rendering logic as well as isolating the useQuery
or useMutation
hooks in a test.
- Clone the repository
- Run
yarn install
- Run
yarn start
- Run
yarn android
oryarn ios
- Run
yarn test
- Run
yarn test:cov
to generate a coverage report, example below
![Screenshot 2023-11-24 at 16 58 47](https://private-user-images.githubusercontent.com/64678409/285513002-abb8881d-f9a0-4eb1-81d9-862df20bd946.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU1OTI0NDMsIm5iZiI6MTcyNTU5MjE0MywicGF0aCI6Ii82NDY3ODQwOS8yODU1MTMwMDItYWJiODg4MWQtZjlhMC00ZWIxLTgxZDktODYyZGYyMGJkOTQ2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA2VDAzMDkwM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNjZjVkNTA0YmVhODYzNmJmYjlmNjZjNmVmYjk4NDY4ODkzMjVmOTI2Y2RmMTM5NDU4ZmIyZTFjZGE1MTBmODEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.2xWI_zHevG8qb6_WnmLarfHNoKI2SXEQipt2Nv7cZLw)
Example app demo https://github.com/lewiscasewell/react-native-msw-template/assets/64678409/46512e9b-7c4a-4503-b345-5c81ebfd7727