问题
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