React Testing Library getById Link to heading
React testing library provides the getByTestId
function, which queries the DOM looking for an element with the id on the data-testid
property.
To query for an actual id
instead:
import { queryByAttribute, render } from "react-testing-library";
const getById = queryByAttribute.bind(null, "id");
const component = renderComponent();
const subComponent = getById(component.container, "my-id");
expect(subComponent).toBeTruthy();