concept test - drive development in category javascript

appears as: test-driven development, test-driven development
Testing JavaScript Applications

This is an excerpt from Manning's book Testing JavaScript Applications.

Then, I’ll give you an overview of the tools available in React’s testing ecosystem, focusing on my library of choice: react-testing-library, which I’ll use to show you how to write your first tests for React applications.

Even though I’ll focus on a single library, I’ll explain how many other libraries work, their pros and cons, and what to consider when choosing tools so that you can make your own decisions depending on the project on which you’re working.

7.1.1  Setting up a React application

To understand how to test a React application, you must learn what’s necessary to make it run in a browser. Only then you’ll be able to replicate the browser’s environment within your tests accurately.

In this sub-section, you’ll learn how to configure a React application for it to run in a browser. During the process, I’ll explain what tools you’ll need, and what each one of them does.

Start by creating an index.html containing a node into which you’ll render your application. This file should also load a script called bundle.js, which will include your application’s JavaScript code.

Listing 7.1. index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Inventory</title>
</head>
<body>
    <div id="app" />
    <script src="bundle.js"></script>  #1
</body>
</html>