Vue Jest别名配置

问题描述 投票:0回答:1

由于moduleNameMapper设置,我想运行Jest时出错。

我尝试了几种方法,但没有任何变化。

复制:

  1. 克隆仓库:https://github.com/zoztorun/reproduce-webpack-alias-error
  2. npm install
  3. npm run test

terminal error ss

vue.js jestjs vue-cli vue-test-utils jest-webpack-alias
1个回答
1
投票

由于使用的是Vue CLI,因此应使用@vue/cli-plugin-unit-jest,可通过以下命令将其添加到Vue CLI项目中:

@vue/cli-plugin-unit-jest

这还将添加带有示例测试的vue add unit-jest 目录,但它不适合项目的测试文件模式,该模式将<rootDir>/test放置在源文件附近。

使结果适应您的项目:

  1. 删除*.spec.js(因为它将不使用,并且因为它指向不存在的<rootDir>/test
  2. HelloWorld.vue中的jest配置编辑为:
package.json
  1. 删除您的{ "jest": { "preset": "@vue/cli-plugin-unit-jest", "testMatch": [ "**/src/**/*.spec.[jt]s?(x)" ] } } NPM脚本,因为test自动添加了自己的@vue/cli-plugin-unit-jest脚本,必须使用它来代替(即,使用test:unit)。
© www.soinside.com 2019 - 2024. All rights reserved.