Skip to content

Commit 4575963

Browse files
committed
feat(tests): add tests for is-multi prop
1 parent 7c68ac6 commit 4575963

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/Select.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,44 @@ describe("single-select option", () => {
269269
});
270270
});
271271

272+
describe("multi-select options", () => {
273+
it("should select an option when clicking on it", async () => {
274+
const wrapper = mount(VueSelect, { props: { modelValue: [], isMulti: true, options } });
275+
276+
await openMenu(wrapper);
277+
await wrapper.get("div[role='option']").trigger("click");
278+
279+
expect(wrapper.props("modelValue")).toStrictEqual([options[0].value]);
280+
expect(wrapper.get(".multi-value").element.textContent).toBe(options[0].label);
281+
});
282+
283+
it("should display non-selected remaining options on the list", async () => {
284+
const wrapper = mount(VueSelect, { props: { modelValue: [], isMulti: true, options } });
285+
286+
await openMenu(wrapper);
287+
await wrapper.get("div[role='option']").trigger("click");
288+
await openMenu(wrapper);
289+
290+
expect(wrapper.findAll(".menu-option").length).toBe(options.length - 1);
291+
});
292+
293+
it("should remove a selected option and be able to select it again", async () => {
294+
const wrapper = mount(VueSelect, { props: { modelValue: [], isMulti: true, options } });
295+
296+
await openMenu(wrapper);
297+
await wrapper.get("div[role='option']").trigger("click");
298+
await openMenu(wrapper);
299+
300+
expect(wrapper.findAll(".menu-option").length).toBe(options.length - 1);
301+
302+
await wrapper.get(".multi-value").trigger("click");
303+
await openMenu(wrapper);
304+
305+
expect(wrapper.findAll(".menu-option").length).toBe(options.length);
306+
expect(wrapper.findAll(".multi-value").length).toBe(0);
307+
});
308+
});
309+
272310
describe("clear button", () => {
273311
it("should display the clear button when an option is selected", async () => {
274312
const wrapper = mount(VueSelect, { props: { modelValue: null, options, isClearable: true } });

0 commit comments

Comments
 (0)