-
Notifications
You must be signed in to change notification settings - Fork 1
/
it.web.react-tests.txt
16 lines (16 loc) · 2.02 KB
/
it.web.react-tests.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Start integrating Tests within your React Apps
As React apps grow in complexity there becomes a higher likelihood that code will break.
Whether abstracting, adding features or refactoring, there always lies the possibility of bugs being introduced — and this is multiplied as more developers start contributing to the project.
The solution we need here are automated tests that can be run in real-time during development.
This article will introduce the tools needed to do this, what types of tests we can carry out in React, and why we would want to do so.
Let’s start the journey of bug free React apps by introducing Jest — the most widely adopted Javascript testing package that Facebook have opted to use as their primary means of testing React apps.
Introducing Jest
The first tool we will visit is Jest. Jest is a node-based test runner allowing fast parallel running of tests in a node environment.
It works out of the box within any Create React App project.
Running npm test in a Terminal window within your app directory will initialise Jest and start testing in watch mode — meaning changes to files will re-run the tests associated with those files immediately as you are developing.
But, what about Mocha?
You may have read about or even used another Javascript testing framework called Mocha; an alternative capable and feature rich package for asynchronous Javascript testing.
Even though this article is Jest focused primarily, it is worth noting that Mocha is another suitable testing framework that also has strong adoption amongst the Javascript community.
At the time of writing Jest on NPM is boasting 3,695,443 weekly downloads, showing a lot more momentum in adoption than the Mocha package, currently on 2,247,393 weekly downloads.
Both packages have been around a while — Jest on 147 releases and Mocha on 146 releases — and their histories have had highs and lows, prompting many online articles to route for one package or the other.
However, it is clear in 2019 that Jest is winning the battle as the dominant React testing suite.