mercredi 16 décembre 2020

How to test checkbox in reactjs with Jest

I am trying to test UI in react with jest. My problem is related to checkbox click. If it's checked, button should appear but it shows error in this part expect(screen.getByTestId("change-modalityButton")).toBeInTheDocument(); I think it's related checkbox. did I check checkbox correctly?

const leftClick = { button: 0 };


test("Change Modality of each Course with SubjectId and Modality", async () => {
    const mockChangeModality = jest.spyOn(API, "changeModalityCourse");
    mockChangeModality.mockReturnValue(
      new Promise((resolve) => resolve())
    );
    const mockNotLoggedUser = jest.fn();
  
    render(<ModifyLecture notLoggedUser={mockNotLoggedUser} />);
  
    userEvent.click(screen.getByTestId("checkAll"), leftClick);
    expect(screen.getByTestId("change-modalityButton")).toBeInTheDocument();
    
    userEvent.click(screen.getByTestId("change-modalityButton"), leftClick);

Aucun commentaire:

Enregistrer un commentaire