使用grunt-contrib-jasmine插件将jQuery加载到Grunt.js中 [英] Loading jQuery into Grunt.js using the grunt-contrib-jasmine plugin

查看:95
本文介绍了使用grunt-contrib-jasmine插件将jQuery加载到Grunt.js中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Grunt.js和grunt-contrib-jasmine插件将jQuery加载到我的测试中。这里是我的Gruntfile.js的一个要点,我在jasmine.options.vendor数组中引用了jQuery作为文档建议。



https ://gist.github.com/anonymous/4751371 然而,当我运行一个非常简单的测试时,它失败了,因为jQuery没有被加载:

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

beforeEach(function(){
$ ul = $('< ul>< li class =no-results>< / li>< / ul>'); $ b $ ();
$ b it('应该测试一些数字的值',function(){
expect(9).toEqual(9);
});

});

任何想法为什么?

解决方案

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

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

关键是使用 http 而不是 https



测试通过。


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?

解决方案

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.

这篇关于使用grunt-contrib-jasmine插件将jQuery加载到Grunt.js中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆