vue.js - 如何将带有 Jest 的 Vue Test Utils 添加到现有的 Vue-CLI 3 项目中?

标签 vue.js vuejs2 vue-cli vue-cli-3 vue-test-utils

我想测试一个已经存在的 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 - 如何将带有 Jest 的 Vue Test Utils 添加到现有的 Vue-CLI 3 项目中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55914263/

相关文章:

vue.js - 检测浏览器关闭或页面更改 VueJs

javascript - Vue watch[fat arrow scope] 提供了错误的 this 上下文

firebase - 如何让 firebase App Check 在 Web 应用程序中与 Cloud Firestore 一起使用

docker - docker下运行vue/cli app simple index.html打开

vue.js - 视觉 : command not found after installing @vue/cli

vue.js - 我如何在 Vue CLI 3 中使用 stylus-resources-loader?

typescript Vue : using a dynamic string name for a method

vue.js - 构建终止 : Build script returned non-zero exit code: 1

javascript - 为什么我的作用域插槽不显示任何内容?

javascript - 模拟 vue 组件依赖