grunt-contrib-jasmine ReferenceError:找不到变量:jQuery

时间:2015-01-11 10:47:45

标签: javascript jquery gruntjs grunt-contrib-jasmine

这是我的Gruntfile jasmine配置任务。我通过供应商选项添加了jquery和jasmine-jquery。

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"
            ]
        }
    },

运行grunt后获取错误。看起来grunt-jasmine并不包括在任务中设置的供应商。

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)

1 个答案:

答案 0 :(得分:2)

哦,这是我的错。供应商需要在内部选项。任务配置应如下所示:

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"
            ]
        },

    }
}