Archi's Academy

BLACK FRIDAY

85% Discount for all November

clock-icon
00days
00hours
00minutes
00seconds
Get in touch

Automation

Testing

Jest is a delightful JavaScript Testing Framework with a focus on simplicity. It works with projects using: Babel, TypeScript, Node, React, Angular, Vue, and more!”

Jest is one of the test frameworks we use, so you may be familiar with it already. This guide explains how to set up Jest in your project, write a unit test, write a snapshot test, and common problems that people encounter when using Jest in React Native.

Jest is an open-source testing framework that has become increasingly popular recently. Initially developed by Facebook, Jest makes it faster and easier to run JavaScript tests by having everything needed to be included in one framework. Jest comes with built-in mocking and assertion libraries, which also run your tests concurrently in parallel, providing faster test execution.

The first thing we'll want to do is install jest-expo, it's a Jest preset that mocks out the native side of the Expo SDK and handles some configuration for you.

To install jest-expo as a development dependency run: yarn add jest-expo --dev or npm i jest-expo --save-dev.

Then we need to add/update package.json to include:

"scripts": 
{  ...  "test": "jest"
},
"jest": 
{  "preset": "jest-expo"
}

Now let's add react-test-renderer to our project:

yarn add react-test-renderer --dev or npm i react-test-renderer --save-dev.

That's it! Now we can start writing the Jest tests!

archis-trainees-blog

Arya Tuba Durgun

Monday, May 10, 2021