Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Jasmine Ajax

I am writing some tests with Jasmine. I am running those tests via Gulp. I want to use the Jasmine Ajax plugin. However, I cannot figure out how to include it into my tests. Right now, I have the following:

tests.js

describe('MyApp', function() {
  beforeEach(function() {
    jasmine.Ajax.install();
  });

  it('should run an ajax request', function() {
    // test ajax
  });
});

Once again, I'm running this via Gulp. So, in my gulpfile.js I have the following:

gulpfile.js

var gulp = require('gulp');
var jasmine = require('gulp-jasmine');

gulp.task('test', function() {
  return gulp
    .src('tests/*.js')
    .pipe(jasmine());
});

When I execute this, I get the following from the command-line:

TypeError: Cannot read property 'install' of undefined.

Its like Jasmine Ajax isn't getting loaded. Yet, I'm not sure how to load it. Can someone please help me solve this issue?

Thank you.

like image 628
xam developer Avatar asked Jun 13 '15 12:06

xam developer


1 Answers

I haven't tested this myself since I don't have enough info to recreate your setup, but you could try to put the mock-ajax.js file in the helpers directory, that is where the default configuration of jasmine-npm, which is used by gulp-jasmine, looks for them.

like image 74
Simon Groenewolt Avatar answered Nov 03 '22 08:11

Simon Groenewolt