Unit Testing React TypeScript app — with Jest, Jest-dom, Enzyme & Sinon

Eli Elad Elrom
Master React
Published in
10 min readOct 19, 2020

--

In the previous article, I have shown how to test a React App using Jest, Jest-dom, and Enzyme for the JavaScript project.

Take a look;

That’s all good and well, however, when your App is based on TypeScript and NOT Javascript, some code changes need to happen. I needed to convert this code into TS as I am using it in my upcoming React 17 book, so sharing the code here in case someone needs to see an example of unit testing with TypeScript instead of Javascript. You can download the entire code from here.

Let’s review the code.

Setting up our TS project

To set up the project I will be using my CRA MHL template project that includes TS as well as many other must-have libraries;

$ yarn create react-app hello-jest-enzyme-ts — template must-have-libraries

Once complete you will get the: “Happy hacking!” message and you can test with “$ yarn start”.

--

--