Skip to content

Commit 70f5198

Browse files
committed
test(SingleSelect): handle empty string value
1 parent 49cd9dd commit 70f5198

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/components/Select/SingleSelect.test.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,46 @@ describe("Select", () => {
138138
expect(getByTestId("select-trigger")).toHaveTextContent("Content0");
139139
});
140140

141+
it("should render initially selected option with empty value", () => {
142+
const OPTION_TEXT = "Empty option";
143+
144+
const { getByTestId } = renderSelect({
145+
value: "",
146+
options: [
147+
{
148+
value: "",
149+
label: OPTION_TEXT,
150+
},
151+
],
152+
});
153+
154+
const selectedValue = getByTestId("select-trigger");
155+
expect(selectedValue.textContent).toBe(OPTION_TEXT);
156+
});
157+
158+
it("should render manually selected option with empty value", () => {
159+
const OPTION_TEXT = "Empty option";
160+
161+
const { queryByText, getByTestId } = renderSelect({
162+
options: [
163+
{
164+
value: "",
165+
label: OPTION_TEXT,
166+
},
167+
],
168+
});
169+
170+
const selectTrigger = getByTestId("select-trigger");
171+
expect(selectTrigger).not.toBeNull();
172+
expect(selectTrigger.textContent).toBe("Select an option");
173+
selectTrigger && fireEvent.click(selectTrigger);
174+
175+
const item = queryByText(OPTION_TEXT);
176+
expect(item).not.toBeNull();
177+
item && fireEvent.click(item);
178+
expect(selectTrigger.textContent).toBe(OPTION_TEXT);
179+
});
180+
141181
it("should close select on selecting item", () => {
142182
const { queryByText } = renderSelect({});
143183
const selectTrigger = queryByText("Select an option");

0 commit comments

Comments
 (0)