const Homepage = () => { const aboutref = useRef(null); const skillref = useRef(null);…
- User
const Homepage = () => { const aboutref = useRef(null); const skillref = useRef(null); const myworkref = useRef(null); const blogref = useRef(null); const contactref = useRef(null); const [scrolled] = useScroll(skillref); const isKeyboardOpen = useDetectKeyboardOpen(); return ( <> <Navigation {...{ aboutref, skillref, myworkref, blogref, contactref }} /> {scrolled && !isKeyboardOpen && ( <div className="page__upper" onClick={() => scrollToRef(aboutref)}> )} </> ); }; export default Homepage; write test in jest for component
- Assistant
import React from "react"; import { render } from "@testing-library/react"; import Homepage from "./Homepage";
describe("Homepage Component", () => { it("renders without crashing", () => { render(); });
it("displays header and main sections", () => { const { getByRole } = render(); const header = getByRole("navigation"); const main = getByRole("main"); expect(header).toBeInTheDocument(); expect(main).toBeInTheDocument(); });
it("displays navigation links", () => { const { getByText } = render(); const aboutLink = getByText("About"); const skillsLink = getByText("Skills"); const myWorksLink = getByText("My Works"); const blogLink = getByText("Blog"); const contactLink = getByText("Contact"); expect(aboutLink).toBeInTheDocument(); expect(skillsLink).toBeInTheDocument(); expect(myWorksLink).toBeInTheDocument(); expect(blogLink).toBeInTheDocument(); expect(contactLink).toBeInTheDocument(); });
it("scrolls up when the upper arrow is clicked", () => { const { getByRole } = render(); const arrow = getByRole("button"); arrow.click(); const pageTop = window.pageYOffset || document.documentElement.scrollTop; expect(pageTop).toEqual(0); }); });