Testing ReactJS
We already know that unit testing involves checking small units, and most often, just functions, which perform some logic and return a result. To understand how testing in ReactJS works, the concept and idea remain the same. We know that at their core, React components are actually createElement
functions that return a node, which, as a result of the render
function, is displayed on the browser screen as HTML elements. In unit testing, we don’t have a browser, but this is not a problem for us since we know that the render target in React can be almost anything. As you may have already guessed, in the unit tests of ReactJS components, we will be rendering components into a specially created JSDOM format, which is fully identical to the DOM, and the React Testing Library will help us with this.
This library contains a set of tools that allow rendering components, simulating events, and then checking the results in various ways.
Before we start, let’...