JSHint thinks Jasmine functions are undefined

喜夏-厌秋 提交于 2019-11-30 05:46:56

You can just add "jasmine": true to your .jshintrc file.

Ian128K

MINOR CORRECTION - there should be "" around predef in the .jshintrc file.

Fixed by adding this to the jshint options in my Gruntfile.coffee:

predef: [
    "jasmine"
    "describe"
    "xdescribe"
    "before"
    "beforeEach"
    "after"
    "afterEach"
    "it"
    "xit"
    "it"
    "inject"
    "expect"
    "spyOn"
]

.jshintrc:

"predef": [
    "jasmine",
    "describe",
    "xdescribe",
    "before",
    "beforeEach",
    "after",
    "afterEach",
    "it",
    "xit",
    "it",
    "inject",
    "expect",
    "spyOn",
]

I fixed this in Gruntfile.js adding jasmine: true to the options of the jshint task:

jshint:
{
    options:
    {
        ...
        node: true,
        jasmine: true,
        ...
    },
    ...
},

Like the OP, I'm not using a .jshintrc file either.

I believe the other answers are correct, but I have never seen such exception before, however I see it now. Then I noticed that my tests are not in IIFE. So I moved them in IIFE like this and I no longer get such JSHINT warnings.

(function () {

  describe('foo', () => {
     it('bar', () => {
        expect(1+1).toEqual(2);
     });
  });

})();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!