前言

今天学习 jest 的 vue-test-utils 的配置及使用。

  1. 报错原因为 jest 全局变量
  2. git 提交代码报错,使用除了参考链接里的解决方案,正好复习一下之前学习的 Git Hooks:
  • 错误 git 日志

    git-error-1675323308267

    ...
    ✖ vue-cli-service lint found some errors. Please fix them and try committing again.
    error: 'describe' is not defined (no-undef) at __tests__\unit\HelloWorld.test.js:5:1:
    ...
    error: 'it' is not defined (no-undef) at __tests__\unit\HelloWorld.test.js:6:3:
    ...
    pre-commit hook failed (add --no-verify to bypass)
    

解决方案

  1. .eslintrc.js
module.exports = {
  env: {
    jest: true // 添加这一行
  },
}

就不报错了。

  1. 复习 Git Hooks

参考链接

关于jestjs:describe在安装jest时未定义

git提交代码会报 vue-cli-service lint found some errors. Please fix them and try committing again