Skip to content

Commit

Permalink
test(SingleSelect): handle empty string value
Browse files Browse the repository at this point in the history
  • Loading branch information
ariser committed Feb 12, 2025
1 parent 49cd9dd commit 70f5198
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/components/Select/SingleSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,46 @@ describe("Select", () => {
expect(getByTestId("select-trigger")).toHaveTextContent("Content0");
});

it("should render initially selected option with empty value", () => {
const OPTION_TEXT = "Empty option";

const { getByTestId } = renderSelect({
value: "",
options: [
{
value: "",
label: OPTION_TEXT,
},
],
});

const selectedValue = getByTestId("select-trigger");
expect(selectedValue.textContent).toBe(OPTION_TEXT);
});

it("should render manually selected option with empty value", () => {
const OPTION_TEXT = "Empty option";

const { queryByText, getByTestId } = renderSelect({
options: [
{
value: "",
label: OPTION_TEXT,
},
],
});

const selectTrigger = getByTestId("select-trigger");
expect(selectTrigger).not.toBeNull();
expect(selectTrigger.textContent).toBe("Select an option");
selectTrigger && fireEvent.click(selectTrigger);

const item = queryByText(OPTION_TEXT);
expect(item).not.toBeNull();
item && fireEvent.click(item);
expect(selectTrigger.textContent).toBe(OPTION_TEXT);
});

it("should close select on selecting item", () => {
const { queryByText } = renderSelect({});
const selectTrigger = queryByText("Select an option");
Expand Down

0 comments on commit 70f5198

Please sign in to comment.