我想测试一个已经存在的Vue CLI 3项目.在创建项目时,我还没有初始化测试预设.我已经搜索过了,但没有找到任何合适的结果.我也阅读了文档,但它说在创建项目时添加测试.

推荐答案

在项目根目录中,输入以下命令以添加@vue/test-utils and jest:

vue add unit-jest

命令输出应类似于以下内容:

$ vue add unit-jest

?  Installing @vue/cli-plugin-unit-jest...

+ @vue/cli-plugin-unit-jest@3.7.0
added 282 packages from 167 contributors, removed 2 packages and audited 42205 packages in 9.693s
found 63 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details
✔  Successfully installed plugin: @vue/cli-plugin-unit-jest


?  Invoking generator for @vue/cli-plugin-unit-jest...
?  Installing additional dependencies...

added 12 packages from 11 contributors, updated 1 package, moved 4 packages and audited 42427 packages in 7.895s
found 64 low severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details
✔  Successfully invoked generator for plugin: @vue/cli-plugin-unit-jest
   The following files have been updated / added:

     jest.config.js
     tests/unit/.eslintrc.js
     tests/unit/example.spec.js
     package-lock.json
     package.json

   You should review these changes with git diff and commit them.

Vue.js相关问答推荐

Vue3组合-如何在组件卸载时注销回调

Vue 2 如何在全局函数中返回观察者

VSelect - Select 不适用于 Vuetify 3 中的自定义项目插槽

VeeValidate 4 字段验证状态

如何在 Nativescript 应用程序中调用 axios/api 调用

VuetifyJS,outer-link 未显示为光标

如何在异步功能上使用 debounce?

是否可以在没有 Vue 的情况下使用 Vuex?

在组件的样式部分使用 Vue 变量

如何在 vuejs 中异步加载图像 src url?

如何创建 vuetify 工具栏链接下拉菜单?

单击链接会更改 url,但不会更改页面上的内容/数据

如何从 .vue 文件中导出多个对象

从 Url 中删除查询字符串参数

验证子组件Vue vee-validate

错误 [ERR_UNSUPPORTED_ESM_URL_SCHEME]:默认 ESM 加载器仅支持文件和数据 URL - Vue 3

Vue 如何使用 slot 和 slot-props 测试组件

Vue.js 处理多次点击事件

Vuetify v-btn 路由活动类问题

NPM:403 禁止 - PUT http://registry.npmjs.org/[package-name] - 禁止