当React/Vite 使用原生自带的测试功能时测试React应用时,若启用了ESLint进行检查,就会有下列报错:
ESLint: 'test' is not defined. (no-undef)
ESLint: 'expect' is not defined. (no-undef)

ESLint 警告关键字 test 和 expect 没有定义。该问题可以通过安装 eslint-plugin-vitest-globals 来解决:
npm install --save-dev eslint-plugin-vitest-globals
并编辑 .eslint.cjs
文件来启用插件,如下所示:
module.exports = {