Skip to content

How can I test that the Lightbox component is opening and closing correctly? #306

Closed Locked Answered by igordanchenko
virusxd521 asked this question in Q&A
Discussion options

You must be logged in to vote

Here is a working example:

import { expect, test, vi } from "vitest";
import { act, render } from "@testing-library/react";

import App from "./App.tsx";

test("App test", () => {
  vi.useFakeTimers();

  try {
    const { queryByLabelText, getByLabelText, getByText } = render(<App />);

    act(() => {
      getByText("Open").click();
    });

    expect(queryByLabelText("Previous")).toBeInTheDocument();
    expect(queryByLabelText("Next")).toBeInTheDocument();
    expect(queryByLabelText("Close")).toBeInTheDocument();

    act(() => {
      getByLabelText("Close").click();
      vi.runAllTimers();
    });

    expect(queryByLabelText("Previous")).not.toBeInTheDocument();
    expect(quer…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@virusxd521
Comment options

@igordanchenko
Comment options

@virusxd521
Comment options

Answer selected by igordanchenko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants