/* ! * (c) Copyright 2025 Palantir Technologies Inc. All rights reserved. */ import { render, screen } from "@testing-library/react"; import { createRef } from "react"; import { describe, expect, test, vi } from "@blueprintjs/test-commons/vitest"; import { Slot } from "./slot"; describe("", () => { test("merges props into a single child", () => { render( , ); const button = screen.getByRole("button", { name: /test/i }); expect(button).toHaveAttribute("id", "foo"); expect(button).toHaveAttribute("data-test", "bar"); }); test("merges className and style", () => { render( , ); const button = screen.getByRole("button", { name: /test/i }); expect(button).toHaveClass("outer"); expect(button).toHaveClass("inner"); expect(button).toHaveStyle({ fontWeight: 700 }); expect(button).toHaveStyle({ fontStyle: "italic" }); }); test("forwards ref to the child", () => { const ref = createRef(); render( , ); expect(ref.current).toBeInstanceOf(HTMLButtonElement); expect(ref.current).toBeInTheDocument(); }); test("returns null if no children are provided", () => { const { container } = render(); expect(container.firstChild).toBeNull(); }); test("throws an error when multiple children are provided", () => { // suppress error logging to keep test output clean const stderrWriteSpy = vi.spyOn(process.stderr, "write").mockImplementation(vi.fn()); const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(vi.fn()); expect(() => { render( , ); }).toThrow("Only single element child is allowed in Slot"); stderrWriteSpy.mockRestore(); consoleErrorSpy.mockRestore(); }); });