Skip to content

Commit

Permalink
test: added new test case for toggle switch
Browse files Browse the repository at this point in the history
  • Loading branch information
yaswanth-deriv committed Mar 26, 2024
1 parent 87aedc6 commit 76dc372
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/components/ToggleSwitch/__test__/ToggleSwitch.spec.tsx
Original file line number Diff line number Diff line change
@@ -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(
<ToggleSwitch onChange={onChange} value={false}/>
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(
<ToggleSwitch onChange={onChange} value={isChecked}/>
);
const toggleSwitch = getByRole("checkbox");
screen.debug();
expect(toggleSwitch).not.toBeChecked();
fireEvent.click(toggleSwitch);
rerender(<ToggleSwitch onChange={onChange} value={isChecked} />);
expect(onChange).toHaveBeenCalledTimes(1);
expect(toggleSwitch).toBeChecked();
});

it("should render and function properly with default Props", () => {
Expand Down

0 comments on commit 76dc372

Please sign in to comment.