【问题标题】:grunt-contrib-jasmine ReferenceError: Can't find variable: jQuerygrunt-contrib-jasmine ReferenceError:找不到变量:jQuery
【发布时间】:2015-01-11 10:47:44
【问题描述】:

这是我的 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)

【问题讨论】:

    标签: javascript jquery gruntjs grunt-contrib-jasmine


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢@jedrzejchalubek,你也救了我的命:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-18
    • 2014-03-07
    • 1970-01-01
    • 2013-02-06
    • 1970-01-01
    • 2016-05-30
    • 2023-03-27
    相关资源
    最近更新 更多