Skip to content

Commit d5a2c66

Browse files
committed
fix(tests): invalid KeyboardEvent dispatched using Space to select option
1 parent fe18c2c commit d5a2c66

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Select.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,14 @@ describe("single-select option", () => {
200200
const wrapper = mount(VueSelect, { props: { modelValue: null, options } });
201201

202202
await openMenu(wrapper);
203-
await dispatchEvent(wrapper, new KeyboardEvent("keydown", { key: "Enter" }));
203+
204+
// Triggering space event with KeyboardEvent constructor is a bit tricky. Must be done like this:
205+
const event = new KeyboardEvent("keydown", {});
206+
Object.defineProperty(event, "code", { value: "Space" });
207+
Object.defineProperty(event, "key", { value: " " });
208+
document.dispatchEvent(event);
209+
210+
await wrapper.vm.$nextTick();
204211

205212
expect(wrapper.emitted("update:modelValue")).toStrictEqual([[options[0].value]]);
206213
expect(wrapper.get(".single-value").element.textContent).toBe(options[0].label);

0 commit comments

Comments
 (0)