Testing basic prop passing in React
import { render, screen } from "@testing-library/react";
describe("<CertificateHtml />", () => {
it("should render the values passed as props", () => {
// Arrange:
const stub = {
titleOfActivityOrProgramme: "Filming",
nameOfDepartment: "The film department",
};
// Act:
render(<CertificateHtml {...stub} />);
// Assert:
expect(screen.getByText("Filming")).toBeInTheDocument();
expect(screen.getByText("The film department")).toBeInTheDocument();
});
});
Or, loop:
for (const entry of Object.values(stub)) {
expect(screen.getByText(entry)).toBeInTheDocument();
}