I am trying to use the jasmine-ajax library to mock ajax request with grunt-contrib-jasmine , but it seems jasmine is not able to find the library (it says jasmine.Ajax is not defined).
my grunt file:
jasmine: {
test:{
src :[ '<%= watch.files %>'],
options: {
vendor: 'vendor/mock-ajax.js',
specs : ['specs/**/*spec.js'],
helpers : 'specs/helpers/*.js',
timeout : 10000
}
}
I downloaded mock-ajax.js and put it in a vendor folder. this is the part of the test where the error appears:
beforeEach(function() {
jasmine.Ajax.install();
});
solved.. for the interest of others with the same problem: the file in https://github.com/pivotal/jasmine-ajax/blob/master/lib/mock-ajax.js did not worked for me. I installed jasmine-ajax via npm and then referenced its version of mock-ajax.js from the gruntfile: vendor: ['node_modules/jasmine-ajax/lib/mock-ajax.js'],
thanks to jsoverson for the hints in checking the paths ( https://github.com/gruntjs/grunt-contrib-jasmine/issues/111#issuecomment-51806488 )
this is the setup of a recent project, I just tested with a fresh "git clone", "npm install", "grunt test", it works out of the box! hope it helps:
jasmine: {
test:{
src :[
'<%= watch.files %>'
],
options: {
vendor: ['node_modules/jasmine-ajax/lib/mock-ajax.js',
'node_modules/jquery/dist/jquery.js',
'node_modules/jasmine-jquery/lib/jasmine-jquery.js',
'node_modules/handlebars/dist/handlebars.js',
],
specs : ['spec/helpers/*.js',
'spec/**/*spec.js'],
helpers : ['spec/helpers/*.js'],
timeout : 10000,
keepRunner: true
}
},
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.