Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 5, 2022 09:26 am GMT

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

SyntaxDescription
itto create test-case
testto create test-case
describeto define the test suits. It groups the test-cases
skipto skip a test-case while running your test-case then you will use skip
todoto 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:

TaskCommands
Executing all test-casesnpm run test
Executing specific test-casenpm run test -- -t 'test-name'
Update Snapshotnpm run test -- -u
Getting Coveragenpm test -- --coverage

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


Original Link: https://dev.to/hellonehha/your-guide-for-testing-reactjs-apps-part-2-a8f

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To