简体   繁体   中英

grunt-contrib-jasmine ReferenceError: Can't find variable: jQuery

Here is my Gruntfile jasmine config task. I've added jquery and jasmine-jquery via vendor options.

jasmine: {
        src: {
            src: '<%= paths.dist %>/**/*.js',
            options: {
                specs: '<%= paths.tests %>/specs/*Spec.js',
                helpers: '<%= paths.tests %>/helpers/*Helper.js',
                outfile: '<%= paths.tests %>/_SpecRunner.html'
            },
            vendor: [
                "<%= paths.bower %>/jquery/dist/jquery.js",
                "<%= paths.bower %>/jasmine-jquery/lib/jasmine-jquery.js"
            ]
        }
    },

After running grunt gets errors. Looks like grunt-jasmine don't including vendors setted in task.

Running "jasmine:src" (jasmine) task
Testing jasmine specs via PhantomJS

>> ReferenceError: Can't find variable: jQuery at
>> dist/script.js:97
 Core
   X should return element
     ReferenceError: Can't find variable: $ in file:///Users/jedrzejchalubek/Dropbox/Script/tests/specs/CoreSpec.js (line 6) (1)
     ReferenceError: Can't find variable: $ in file:///Users/jedrzejchalubek/Dropbox/Script/tests/specs/CoreSpec.js (line 10) (2)

Oh, It's my fault. Vendor need to be inside options. Task config should look like this:

jasmine: {
    src: {
        src: '<%= paths.dist %>/**/*.js',
        options: {
            specs: '<%= paths.tests %>/specs/*Spec.js',
            helpers: '<%= paths.tests %>/helpers/*Helper.js',
            outfile: '<%= paths.tests %>/_SpecRunner.html',
            vendor: [
                "<%= paths.bower %>/jquery/dist/jquery.js",
                "<%= paths.bower %>/jasmine-jquery/lib/jasmine-jquery.js"
            ]
        },

    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM