JSHint thinks Jasmine functions are undefined

12,505

Solution 1

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

Solution 2

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.

Share:
12,505
Admin
Author by

Admin

Updated on July 04, 2022

Comments

  • Admin
    Admin almost 2 years

    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 built-in functions. For example:

    Running "jshint:test" (jshint) task
    
       js/main.spec.js
          3 |describe("loadMatrix()", function() {
             ^ 'describe' is not defined.
          4 |    it("should not assign a value if no arg is passed.", function() {
                 ^ 'it' is not defined.
    

    (I also get some undefined errors for the variables and functions from the JS file that my spec is meant to test against, but I'm not sure why that is and it may be a separate issue.)

    My Karma config file has frameworks: [ "jasmine" ] in it, I don't have any globals set for JSHint, and I don't have a .jshintrc file since I'm configuring it in Grunt. I did try adding Jasmine's functions as JSHint globals in my Gruntfile at one point, but setting them as either true or false didn't make a difference—the errors still persisted when JSHint ran.

    What am I missing? I can't seem to do anything to get JSHint to skip definition checking for Jasmine's functions in my spec file.