【问题标题】:Loading jQuery into Grunt.js using the grunt-contrib-jasmine plugin使用 grunt-contrib-jasmine 插件将 jQuery 加载到 Grunt.js
【发布时间】:2013-02-10 22:55:24
【问题描述】:

我正在尝试使用 Grunt.js 和 grunt-contrib-jasmine 插件将 jQuery 加载到我的测试中。这是我的 Gruntfile.js 的要点,我在 jasmine.options.vendor 数组中引用了 jQuery,正如 documentation 所建议的那样。

https://gist.github.com/anonymous/4751371

但是,当我运行一个非常简单的测试时,它失败了,因为 jQuery 没有被加载:

describe('like module', function() {
    var $ul;

    beforeEach(function() {
        $ul = $('<ul><li class="no-results"></li></ul>');
    });

    it('should test the value of some numbers', function() {
        expect(9).toEqual(9);
    });

});

知道为什么吗?

【问题讨论】:

  • 您通过 CDN 加载 jQuery。您是否尝试过使用本地安装的 jQuery?
  • 是的,当您使用 jQuery 的本地副本时它可以工作。有点烦人,但至少它有效。
  • 我觉得是bug,对比一下这个issue:github.com/gruntjs/grunt-contrib-jasmine/issues/18
  • 能够做到这一点会很有用。我尝试了 grunt-contrib-jasmine-requirejs 插件,但也无法正常工作。

标签: jasmine gruntjs


【解决方案1】:

我遇到了同样的问题。在看到@ludder 的链接后,我将 Jasmine 任务配置更改为:

jasmine: {
  src: ['./someFile.js'],
    options: {
      specs: 'test/*Spec.js',
      keepRunner : false,
      vendor: 'http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'
    }
  }

关键是使用http https

测试正在通过。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 2013-02-06
    • 2014-11-19
    • 2016-05-30
    • 1970-01-01
    相关资源
    最近更新 更多