From 617f163067697af539f9c59acebfc960928dd690 Mon Sep 17 00:00:00 2001 From: Farhan Ahmad Nurzi Date: Mon, 22 Apr 2024 12:04:04 +0800 Subject: [PATCH] fix: testcase --- .../PageLayout/__test__/PageLayout.spec.tsx | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/src/components/PageLayout/__test__/PageLayout.spec.tsx b/src/components/PageLayout/__test__/PageLayout.spec.tsx index 569b2573..7f44bd1a 100644 --- a/src/components/PageLayout/__test__/PageLayout.spec.tsx +++ b/src/components/PageLayout/__test__/PageLayout.spec.tsx @@ -1,42 +1,47 @@ import React from "react"; import { render, screen } from "@testing-library/react"; import { PageLayout } from ".."; -import * as hooks from "../../../hooks" +import * as hooks from "../../../hooks"; // Mocking the useDevice hook jest.mock("../../../hooks", () => ({ - useDevice: jest.fn().mockReturnValue({isMobile:false}), + useDevice: jest.fn().mockReturnValue({ isMobile: false }), })); describe("PageLayout Component", () => { - it("renders children correctly", () => { - render( - -
Content
-
- ); - const content =screen.getByText("Content") - expect(content).toBeInTheDocument(); - }); + it("renders children correctly", () => { + render( + +
Content
+
, + ); + const content = screen.getByText("Content"); + expect(content).toBeInTheDocument(); + }); - it("renders sidebar when provided and not on mobile", () => { - const sidebar =
Sidebar
; - render(); - const sidebarContent =screen.getByText("Sidebar") - expect(sidebarContent).toBeInTheDocument(); - }); + it("renders sidebar when provided and not on mobile", () => { + const sidebar =
Sidebar
; + render(); + const sidebarContent = screen.getByText("Sidebar"); + expect(sidebarContent).toBeInTheDocument(); + }); - it("does not render sidebar on mobile", () => { - jest.spyOn(hooks,'useDevice').mockImplementation(()=>({isMobile:true, isDesktop:false, isTablet:false})) - const sidebar =
Sidebar
; - render(); - const sidebarContent =screen.queryByText("Sidebar") - expect(sidebarContent).not.toBeInTheDocument() - }); + it("does not render sidebar on mobile", () => { + jest.spyOn(hooks, "useDevice").mockImplementation(() => ({ + isMobile: true, + isDesktop: false, + isTablet: false, + isTabletPortrait: false, + })); + const sidebar =
Sidebar
; + render(); + const sidebarContent = screen.queryByText("Sidebar"); + expect(sidebarContent).not.toBeInTheDocument(); + }); - it("does not render sidebar when not provided", () => { - render(); - const sidebarContent=screen.queryByTestId("sidebar") - expect(sidebarContent).toBeNull(); - }); + it("does not render sidebar when not provided", () => { + render(); + const sidebarContent = screen.queryByTestId("sidebar"); + expect(sidebarContent).toBeNull(); + }); });