Search code examples
javascriptajaxgruntjsjasminegrunt-contrib-jasmine

how to make work jasmine-ajax with grunt-contrib-jasmine


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

Solution

  • 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)