DEV Community

Neha Sharma
Neha Sharma

Posted on

Your Guide for Testing ReactJS Apps - Part 2

In the last post you saw the basics of the testing.

Part 1

In this blog, we will continue to learn more about testing basics before getting into code (trust me once we will kickoff coding this theory would come handy)

In the world of testing there are 2 important things:

  1. Task runner: Jest, Chai, Enzyme

  2. Test Library: Airbnb Testing Library and React Testing
    Library

We will be using React Testing Library and Jest for this series.

Type of testing:

  1. TDD: Test Driven Development

  2. BDD: Behavioural Driven Development

In an ideal world we should be following TDD. For this series we I will follow TDD.

TDD ( Test Driven Development)

TDD is about where we write the test-cases first before writing the code. All the test-cases will fail and then we will write the code to make the test-cases pass.

Here, we are writing test-cases first and code later.

Image description

Test suits and Test cases

Syntax Description
it to create test-case
test to create test-case
describe to define the test suits. It groups the test-cases
skip to skip a test-case while running your test-case then you will use skip
todo to mark a test-case as todo. It won't impact the test-coverage but will show how many test-cases are in todo state

How to measure test-cases success?

To measure the test-cases success it is to look at the coverage of the test-cases. From 75%-85% is a good target.

This is how the coverage looks:

Image description

Important commands:

Task Commands
Executing all test-cases npm run test
Executing specific test-case npm run test -- -t 'test-name'
Update Snapshot npm run test -- -u
Getting Coverage npm test -- --coverage

In next blog, we will start writing our first test-case. If you like this blog then do follow me at Twitter.

Top comments (0)