Member-only story
Testing-Library
Testing Library is a lightweight and simple testing library for testing frontend code, and libraries like React and Vue. It gives us a couple key functions for adding and removing our components from a virtual DOM, and checking the contents of the items we render. The core library is built for Vanilla JS (without a framework) but there are addon utility functions for testing React and Vue. The documents for the library can be found here.
The testing-library npm module was built for running browser tests on servers, that wouldn’t have access to the browser APIs for rendering DOM nodes or other features. We will use it as a shortcut, combining a couple key methods of the library with jest (a full-featured testing library).
The primary reason that testing-library exists is because it is much faster to test Frontend JS code if you don’t need to spin up the entire browser runtime environment. The framework is built off the fact that most of the tests that we would want to run to test our interfaces are really simple DOM interactions, like rendering some HTML to the DOM and clicking or interacting with the DOM in basic ways. You don’t need the whole browser environment spun up to do that.
Testing library says about their philosophy: