Introduction
You want to write test cases that are easy to maintain and give you high confidence that your components are functioning properly for your users. You want your tests to avoid including implementation details as part of this goal so that refactoring your components (changes to the implementation but not the functionality) doesn't break them and slow you and your team down. The core library, DOM Testing Library, is a lightweight solution for querying and interacting with DOM nodes to test web pages. So Let us dive into the article!
DOM Testing Library
The core library, DOM Testing Library, is a lightweight solution for querying and interacting with DOM nodes to test web pages (whether simulated with JSDOM/Jest or in the browser). Its main features include searching the DOM for nodes in a similar way to how a user searches for elements on a page. As a result, the library aids in ensuring that your tests give you confidence that your application will work when it is used by a real user.
Several frameworks, including React, Angular, and Vue, have been wrapped around the core library to provide ergonomic APIs. There's also a Cypress plugin that uses testing-library queries for end-to-end tests, as well as a React Native implementation.
This library is not a test runner or framework or specific to a testing framework. Any environment that provides DOM APIs, such as Jest, Mocha + JSDOM, or a real browser, can use the DOM Testing Library.