import { render } from "@testing-library/react" test("should open menu when clicked", () => { const { getByRole } = render(<MyMenu />) expect(getByRole("menu")).not.toBeVisible() const menuTrigger = getByRole("button") menuTrigger.click() expect(getByRole("menu")).toBeVisible() })
import { render } from "@testing-library/react" import userEvent from "@testing-library/user-event" test("should focus the button after pressing tab", async () => { const user = userEvent.setup() const { getByRole } = render(<MyComponent />) const button = getByRole("button") expect(button).not.toHaveFocus() await user.tab() expect(button).toHaveFocus() })