Recently I decided to write tests for my expo react native app written in typescript. Having done this in Reactjs, I didn't expect its native counterpart to be such a pain. I did the usual reading of documentations, checking StackOverflow and there was nothing. I couldn't find any working test or a proper documentation for setting up tests for expo react native apps written in typescript. I must add that I initialised my expo app using a blank template. Using either the tabs or the minimal template automatically sets up test for you (I learnt this much matter).
It seemed like it was recently put there as an answer to my prayer. I had to take it for a spin. Ah!! yes it worked. Also, seeing that I didn't want to use its template, I had to study the repo and replicate the configurations used in my already existing expo app.
let me walk you through how I added jest and react-test-renderer to my already existing expo app in 4 simple steps.
LIST OF DEPENDENCIES USED
1) React-test-renderer
2) jest
3) jest-expo
4) ts-jest
5) jest-coverage-badges
6) @types/jest
7) @types/react-test-renderer
STEPS:
1) Install all the listed dependencies above best with --save-dev flag to see these in your devDependencies.
4) Add scripts for running your tests in different modes in your package.json.
//package.json"test":"jest","test:watch":"npm run test --watch","test:ci":"npm run test --coverage","test:badges":"npm run test:ci && jest-coverage-badges --input coverage/coverage-summary.json --output __badges__"
Now we can go ahead to check if this works
I will have two files here: App.tsx and App.test.tsx