我正在尝试模拟<select>在 Vitest 测试中的元素中选择一个选项。<select>模拟选择应设置绑定到s的 ref 的值v-model。正如您在下面看到的,我根据此处和互联网上其他地方的其他问题尝试了许多不同的方法,但我就是无法使其在我的情况下发挥作用。
我正在使用以下内容:
我创建了一个非常基本的 Vue 组件,其中包括标题和元素<select>:
<script setup lang="ts">
import { ref } from "vue";
const items = ["item 1", "item 2", "item 3", "item 4", "item 5"];
const selectedItem = ref<string>("");
// this is a placeholder for a more complex function
async function handleSubmit(): Promise<void> {
console.log("in handleSubmit()");
console.log(quotedString(selectedItem.value));
}
// this is just here for a prettier output
function quotedString(s: string): …Run Code Online (Sandbox Code Playgroud)