--- tags: - javascript - react - testing --- # Test: Routing on link click ## Component ```jsx const CertificateHtmlLink = () => { return (
View HTML version
); }; ``` ## Test ```js import { render, fireEvent } from "@testing-library/react"; import { Router } from "react-router-dom"; describe(" { it("should link to dynamic HTML certificate page URL on click event", () => { // Arrange: const history = createMemoryHistory({ initialEntries: ["/"] }); // Act: const { getByText } = render( ); // Assert: expect(history.location.pathname).toBe("/"); fireEvent.click(getByText("View HTML version")); expect(history.location.pathname).toBe("/certificate/123"); }); }); ```