What is @types/testing-library__jest-dom?
The @types/testing-library__jest-dom package provides TypeScript type definitions for the jest-dom library, which extends Jest's default matchers to provide more expressive assertions for DOM nodes. This allows developers to write more readable and maintainable tests when using Jest with the DOM or React components.
What are @types/testing-library__jest-dom's main functionalities?
toBeVisible
Checks if an element is visible to the user. This means that the element is not only displayed (i.e., it does not have a CSS display value of 'none'), but also has a non-zero size and is not hidden by other elements.
expect(element).toBeVisible();
toHaveTextContent
Asserts that a given DOM element has text content that matches the expected text, which can be a string or a regular expression.
expect(element).toHaveTextContent('text');
toHaveAttribute
Ensures that a DOM element has an attribute with a specific value. This is useful for checking if elements have the correct attributes set, such as links with the correct href values.
expect(element).toHaveAttribute('href', 'https://example.com');
toHaveClass
Verifies that a DOM element has a particular class or classes. This matcher can take a single class name as a string, or an array of class names to check for multiple classes.
expect(element).toHaveClass('class-name');
toBeChecked
Asserts that an input element of type checkbox or radio is checked. This is useful for ensuring that form elements are in the expected state in response to user interactions or initial conditions.
expect(checkbox).toBeChecked();
Other packages similar to @types/testing-library__jest-dom
chai-dom
chai-dom is a plugin for the Chai assertion library that provides a set of assertions similar to jest-dom, but for use with Chai. It allows developers to make assertions about the DOM when using Mocha or other testing frameworks that support Chai.
expect-puppeteer
expect-puppeteer is a set of custom matchers for Jest to test with Puppeteer. While it focuses on interactions with a headless browser and is more end-to-end oriented, it provides similar functionalities in terms of asserting DOM states and content.
jasmine-dom
jasmine-dom offers DOM-specific matchers for the Jasmine testing framework, similar to what jest-dom provides for Jest. It allows developers using Jasmine to write more expressive assertions about the DOM.