sdlc-hub/web/src/ui/Dropdown.test.tsx
2026-10-22 00:09:46 +04:00

17 lines
827 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { fireEvent, render, screen } from "@testing-library/react";
import { StrictMode } from "react";
import { describe, expect, it, vi } from "vitest";
import { Dropdown } from "./Menu.tsx";
describe("Dropdown (T12.1)", () => {
it("onOpen вызывается один раз на открытие, в том числе в StrictMode", () => {
const onOpen = vi.fn();
render(<StrictMode><Dropdown onOpen={onOpen} button={({ toggle }) => <button onClick={toggle}>открыть</button>}>{() => <p>меню</p>}</Dropdown></StrictMode>);
fireEvent.click(screen.getByText("открыть"));
expect(onOpen).toHaveBeenCalledTimes(1);
expect(screen.getByText("меню")).toBeInTheDocument();
fireEvent.click(screen.getByText("открыть"));
expect(onOpen).toHaveBeenCalledTimes(1);
});
});