相关疑难解决方法(0)

Vue3 的 Vue 测试实用程序:文档未定义

我尝试根据以下内容引导一个简单的应用程序Vue3,,ViteVitest

\n

我还安装了 vue 3 兼容版本的vue test utils来测试 vue 组件。

\n

我在尝试复制文档中的基本示例时遇到错误:

\n
import { mount } from "@vue/test-utils";\nimport { expect, test } from \'vitest\'\n\n\n// The component to test\nconst MessageComponent = {\n  template: "<p>{{ msg }}</p>",\n  props: ["msg"],\n};\n\ntest("displays message", () => {\n  const wrapper = mount(MessageComponent, {\n    props: {\n      msg: "Hello world",\n    },\n  });\n\n  // Assert the rendered text of the component\n  expect(wrapper.text()).toContain("Hello world");\n});\n\n
Run Code Online (Sandbox Code Playgroud)\n
 FAIL  src/tests/hello-world.test.ts > displays message\nReferenceError: document is not defined\n …
Run Code Online (Sandbox Code Playgroud)

vue.js vue-test-utils vite

20
推荐指数
3
解决办法
1万
查看次数

标签 统计

vite ×1

vue-test-utils ×1

vue.js ×1