简体   繁体   English

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

[英]How to add Vue Test Utils with Jest to already existing Vue-CLI 3 project?

I want to test an already existing Vue-CLI 3 project.我想测试一个已经存在的 Vue-CLI 3 项目。 I haven't initialized the testing preset when I was creating the project.我在创建项目时没有初始化测试预设。 I have searched, but haven't found any suitable results.我已经搜索过,但没有找到任何合适的结果。 I read the documentation also, but it said to add testing when creating the project.我也阅读了文档,但是它说在创建项目时要添加测试。

From your project root directory, enter the following command to add @vue/test-utils and jest :在项目根目录中,输入以下命令以添加@vue/test-utilsjest

vue add unit-jest

The command output should look similar to this:命令输出应与此类似:

$ 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.

I was successful with the following plugin:我成功使用了以下插件:

@vue/cli-plugin-unit-jest ([ https://www.npmjs.com/package/@vue/cli-plugin-unit-jest ) @vue/cli-plugin-unit-jest ([ https://www.npmjs.com/package/@vue/cli-plugin-unit-jest )

I installed it, from the root folder, using the command:我使用以下命令从根文件夹安装它:

vue add unit-jest

The command already adds an entry to my package.json file:该命令已将一个条目添加到我的 package.json 文件中:

"scripts": {
    ...
    "test:unit": "vue-cli-service test:unit",
    ...
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM