JSHint thinks Jasmine functions are undefined

前端 未结 4 1952
自闭症患者
自闭症患者 2020-12-29 20:34

I\'ve got a Grunt setup which uses Karma+Jasmine and JSHint. Whenever I run JSHint on my spec file, I get a series of \"undefined\" errors, most of which are for Jasmine\'s

相关标签:
4条回答
  • 2020-12-29 21:11

    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.

    0 讨论(0)
  • 2020-12-29 21:22

    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);
         });
      });
    
    })();
    
    0 讨论(0)
  • 2020-12-29 21:23

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

    0 讨论(0)
  • 2020-12-29 21:23

    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",
    ]
    
    0 讨论(0)
提交回复
热议问题