首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >安装jest时未定义describe

安装jest时未定义describe
EN

Stack Overflow用户
提问于 2019-04-23 17:08:56
回答 2查看 21.4K关注 0票数 56

我在我的项目中使用以下命令安装了jest v24.7.1

代码语言:javascript
运行
复制
npm install jest -D

然后我开始写一些测试文件,但是我得到了这些eslint错误:

代码语言:javascript
运行
复制
'describe' is not defined. eslint (no-undef)
'it' is not defined. eslint (no-undef)
'expect' is not defined. eslint (no-undef)

eslintrc.js:

代码语言:javascript
运行
复制
module.exports = {


env: {
    browser: true,
    es6: true
  },
  extends: ["airbnb", "prettier", "prettier/react"],
  globals: {
    Atomics: "readonly",
    SharedArrayBuffer: "readonly"
  },
  parserOptions: {
    ecmaFeatures: {
      jsx: true
    },
    ecmaVersion: 2018,
    sourceType: "module"
  },
  plugins: ["react"],
  rules: {}
};

我应该添加另一个规则或插件来解决这个问题吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-04-23 17:36:08

.eslintrc.js文件中添加以下行

代码语言:javascript
运行
复制
"env": {
    "jest": true
}

代码语言:javascript
运行
复制
{
  "plugins": ["jest"]
},
"env": {
  "jest/globals": true
}

有关更多详细信息,请查看here,它也定义了相同的内容。

希望你安装的是eslint-plugin-jest package.If,而不是Documentation

Configuring ESLint的所有配置详细信息。

票数 153
EN

Stack Overflow用户

发布于 2020-09-03 10:05:51

在文件头中添加以下注释行

代码语言:javascript
运行
复制
/* globals describe, expect, it */ 
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55807824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档