Can't get rendered element when testing with Jest and selecting with screen.getByTestId
Unanswered
Bell's Vireo posted this in #help-forum
Bell's VireoOP
I am setting my main element like this:
this is the only element with that value for data-testid
then I am trying to get that element
but still getting error: TestingLibraryElementError: Unable to find an element by: [data-testid="someid"]
<main className="w-screen flex flex-col mb-8" data-testid="someid">this is the only element with that value for data-testid
then I am trying to get that element
import { render, screen } from "@testing-library/react";
import Home from "@/pages/index";
import "@testing-library/jest-dom";
describe("Home", () => {
it("renders a heading", () => {
render(<Home />);
const heading = screen.getByTestId("someid");
expect(heading).toBeInTheDocument();
});
});but still getting error: TestingLibraryElementError: Unable to find an element by: [data-testid="someid"]