From 76dc3728d62c1f0ad2906c3639defc41ae1f43ba Mon Sep 17 00:00:00 2001 From: yaswanth-deriv Date: Tue, 26 Mar 2024 11:36:15 +0400 Subject: [PATCH] test: added new test case for toggle switch --- .../__test__/ToggleSwitch.spec.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/ToggleSwitch/__test__/ToggleSwitch.spec.tsx b/src/components/ToggleSwitch/__test__/ToggleSwitch.spec.tsx index 34e0b0b2..392b06c3 100644 --- a/src/components/ToggleSwitch/__test__/ToggleSwitch.spec.tsx +++ b/src/components/ToggleSwitch/__test__/ToggleSwitch.spec.tsx @@ -1,18 +1,24 @@ import React from "react"; -import { render, fireEvent,screen } from "@testing-library/react"; +import { render, fireEvent } from "@testing-library/react"; import { ToggleSwitch } from ".."; describe("ToggleSwitch Component", () => { - fit("checks if value has been set to false before firing event and true after firing event", () => { - const onChange = jest.fn() - const { getByRole } = render( - + it("checks if value has been set to false before firing event and true after firing event", () => { + let isChecked =false; + const onChange = jest.fn(() => { + isChecked = !isChecked; // Toggle isChecked when onChange is called + console.log(isChecked,"value") + }); + const { getByRole,rerender } = render( + ); const toggleSwitch = getByRole("checkbox"); - screen.debug(); + expect(toggleSwitch).not.toBeChecked(); fireEvent.click(toggleSwitch); + rerender(); expect(onChange).toHaveBeenCalledTimes(1); + expect(toggleSwitch).toBeChecked(); }); it("should render and function properly with default Props", () => {