【问题标题】:Jasmine not loading vendor optionsJasmine 未加载供应商选项
【发布时间】:2015-03-11 12:52:14
【问题描述】:

我正在尝试设置一个示例 Jasmine 应用程序,但似乎在包含 jQuery 时我犯了一个错误。 我的 Gruntfile 看起来像这样:

module.exports = function(grunt) {

    // Project configuration.
    grunt.initConfig({
        jasmine: {
            src: 'src/**/*.js',
            specs: 'spec/**/*.js',
            options: {
                vendor: 'bower_components/jquery/dist/jquery.js'
            }
        }
    });

    grunt.loadNpmTasks('grunt-jasmine-runner');


    // Default task.
    grunt.registerTask('default', 'jasmine');

};

我有一个规范文件,它在某处引用了$,它会失败并显示以下消息:

ReferenceError: Can't find variable: $
    at http://127.0.0.1:8888/spec/PlayerSpec.js:14
    at http://127.0.0.1:8888/node_modules/grunt-jasmine-runner/jasmine/lib/jasmine-core/jasmine.js:1035
    at http://127.0.0.1:8888/node_modules/grunt-jasmine-runner/jasmine/lib/jasmine-core/jasmine.js:2034
    at http://127.0.0.1:8888/node_modules/grunt-jasmine-runner/jasmine/lib/jasmine-core/jasmine.js:2024

jquery.js 的路径绝对正确。如果我删除 $ 引用,则规范通过。

【问题讨论】:

    标签: jquery testing gruntjs jasmine bower


    【解决方案1】:

    您的问题的原因是grunt-jasmine-runner 不支持grunt 0.4+,并且它没有vendor 选项。而是使用适用于 grunt 0.4+ 的更新版 grunt-contrib-jasmine

    【讨论】:

    • 路径绝对正确(使用外部路径运行它也不起作用)。我认为我的错误是没有将jquery.js 添加到src。如果我将specs 移动到options,则不再执行任何规范:“0 规范,0 秒内失败。”
    • 真的很奇怪,你使用的是基本配置:(。如果你把你的vendor作为一个数组而不是字符串会发生什么?
    • 同样的事情......我正在使用这个示例项目github.com/jsoverson/grunt-jasmine-runner-example,它可以开箱即用(即使spec 也不在options 中)。但是,只要我引用 $,规范就会失败。
    • grunt-jasmine-runner 不支持 grunt 0.4+:github.com/jasmine-contrib/grunt-jasmine-runner。我建议你安装 grunt-jasmine 并放入我的配置。
    • 我还看到 grunt-jasmine-runner 没有供应商选项。这就是问题的原因。
    猜你喜欢
    • 2015-10-02
    • 2013-09-03
    • 2022-11-16
    • 1970-01-01
    • 2016-09-23
    • 2016-11-08
    • 2015-09-30
    • 2015-11-20
    • 1970-01-01
    相关资源
    最近更新 更多