如何使用Jest将Vue Test Utils添加到现有Vue-CLI 3项目中?

Luc*_*fer 7 vue.js vuejs2 vue-cli vue-test-utils vue-cli-3

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

ton*_*y19 7

在项目的根目录中,输入以下命令以添加@vue/test-utilsjest

vue add @vue/unit-jest
Run Code Online (Sandbox Code Playgroud)

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

$ vue add @vue/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.
Run Code Online (Sandbox Code Playgroud)