JavaScript标准样式无法识别Mocha [英] JavaScript Standard Style does not recognize Mocha

查看:104
本文介绍了JavaScript标准样式无法识别Mocha的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个摩卡测试文件,如下所示:

I have a Mocha test file that looks like this:

var expect = require('chai').expect
var muting = require('../muting')

describe('muting', function () {
  describe('init()', function () {
    it('should inject an object into twitter', function () {
      var twitter = 'twitter'
      muting.init(twitter)
      expect(muting.twitter).to.equal(twitter)
    })
  })
})

当我从CLI运行 mocha 时,它会成功运行测试。

When I run mocha from the CLI, it runs the test successfully.

当我运行标准时( JavaScript标准样式)我在Mocha的框架函数上遇到错误,如下所示:

When I run standard (the executable for JavaScript Standard Style) I get errors on Mocha's framework functions like so:

standard: Use JavaScript Standard Style (https://github.com/feross/standard)   
c:\..\test\index.js:5:0: 'describe' is not defined.  
c:\..\test\index.js:6:2: 'describe' is not defined.  
c:\..\test\index.js:7:4: 'it' is not defined.

什么是最简单的方法让Standard不要抱怨这些功能?

What's the cleanest way to make Standard not complain about these functions?

推荐答案

实际上,您不需要列出package.json中的每一个全局变量。

Actually, you don't need to list every single global variable in your package.json

您可以指定环境,如下所示:

You can specify environments instead like this:

"standard": {
  "env": [ "mocha" ]
}

资料来源:官方ESLint配置文档

这篇关于JavaScript标准样式无法识别Mocha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆