Skip to content

Instantly share code, notes, and snippets.

@schalkneethling
Last active December 16, 2015 13:39
Show Gist options
  • Save schalkneethling/82027b2eacdec7230fa9 to your computer and use it in GitHub Desktop.
Save schalkneethling/82027b2eacdec7230fa9 to your computer and use it in GitHub Desktop.
Intercept and mock Ajax calls with Jasmine-Ajax
/* For reference read the Jasmine and Sinon docs
* Jasmine docs: http://pivotal.github.io/jasmine/
*/
/* global describe, beforeEach, afterEach, it, expect */
describe('ajax.js', function() {
'use strict';
var request;
var success;
describe('on success', function () {
beforeEach(function() {
jasmine.Ajax.install();
});
afterEach(function() {
jasmine.Ajax.uninstall();
});
it('should load JSON', function() {
var result = AjaxModule.loadJSON();
request = jasmine.Ajax.requests.mostRecent();
request.respondWith(TestResponses.loadJSON.success);
expect(request.url).toBe('http://localhost:4000/en-US/data.json');
});
});
});
var TestResponses = {
loadJSON: {
success: {
status: 200,
responseText: '{"message":"Would you like to see this page in your language?","accept":"Yes, please!","cancel":"No, thanks.","update_message":"Looks like you’re using an older version of Firefox.","update_accept":"Update to stay fast and safe.","update_cancel":"Later","latestfx":"42.0"}'
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment