LoginSignup
14
16

More than 5 years have passed since last update.

jshintで 'describe' is not defined 的なエラーが出るやつ。

Last updated at Posted at 2014-07-19

何の話??

定義されてませんよ系のエラーが出た場合の対処法の話です。
変数が外部ファイルで宣言されていた場合なんかに発生します。

mochaだと、こういうのとか。

'describe' is not defined. 
'it' is not defined. 
'before' is not defined.

対処方法1

.jshintrcにこんな感じで記述(必要に合わせて追加)

"globals": {
  "describe"   : false,
  "it"         : false,
  "before"     : false
},

対処方法2

ファイル単位で設定する方法。対象のファイルにこんな感じでコメントを追加。

/*global describe, it, before */

対処方法3

ブロック単位で指定する方法。コメントで囲った範囲内に対して、jshint自体を効かないようにする。
他のエラーも無視してしまうので、定義されてませんよ。の対処法としては微妙。。。

/* jshint ignore:start */
describe('foo', function () {
  it('bar', function () {
    expect(john).to.be.a(doe);
  });
});
/* jshint ignore:end */

対処方法4

行単位で指定する方法。上と同じく、記述した行に対してjshintを効かないようにする。
同じ理由で対処法としては微妙。

describe('foo', function () {      // jshint ignore:line
  it('bar', function () {          // jshint ignore:line
    expect(john).to.be.a(doe);
  });
});

その他設定項目に関しては公式のドキュメントで。

(`・ω・´)ゞ

14
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
16