UNPKG

@crossed/ui

Version:

A universal & performant styling library for React Native, Next.js & React

39 lines (38 loc) 1.57 kB
import { jsx } from "react/jsx-runtime"; import { render, fireEvent, screen } from "@crossed/test"; import { SelectMonth } from "../SelectMonth"; jest.mock("../../Select", () => ({ Select: ({ value, onChange, items }) => /* @__PURE__ */ jsx("select", { value, onChange: (e) => onChange(e.target.value), children: items.map((item) => /* @__PURE__ */ jsx("option", { value: item.value, children: item.label }, item.value)) }) })); describe("SelectMonth", () => { const mockMonths = [ { value: "0", label: "January" }, { value: "1", label: "February" }, { value: "2", label: "March" } ]; const mockOnChange = jest.fn(); test("renders correctly with given months and selected month", () => { render( /* @__PURE__ */ jsx(SelectMonth, { month: 1, months: mockMonths, onChange: mockOnChange }) ); expect(screen.getByDisplayValue("February")).toBeInTheDocument(); }); test("calls onChange when a new month is selected", () => { render( /* @__PURE__ */ jsx(SelectMonth, { month: 1, months: mockMonths, onChange: mockOnChange }) ); fireEvent.change(screen.getByDisplayValue("February"), { target: { value: "2" } }); expect(mockOnChange).toHaveBeenCalledWith(2); }); test("renders all months in the dropdown", () => { render( /* @__PURE__ */ jsx(SelectMonth, { month: 1, months: mockMonths, onChange: mockOnChange }) ); mockMonths.forEach((month) => { expect(screen.getByText(month.label)).toBeInTheDocument(); }); }); }); //# sourceMappingURL=SelectMonth.spec.js.map