Loading jQuery into Grunt.js using the grunt-contrib-jasmine plugin

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 12:36:50

问题


I am trying to load jQuery into my tests using Grunt.js and the grunt-contrib-jasmine plugin. Here is a gist of my Gruntfile.js and I've referenced jQuery in the jasmine.options.vendor array as the documentation suggests.

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

However, when I run a very simple test, it fails because jQuery isn't getting loaded:

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);
    });

});

Any idea why?


回答1:


I had the same problem. After having seen the link by @ludder, I have changed my Jasmine task config to:

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'
    }
  }

The key is to use http and not https.

Tests are passing now.



来源:https://stackoverflow.com/questions/14803583/loading-jquery-into-grunt-js-using-the-grunt-contrib-jasmine-plugin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!