Last active
December 16, 2015 13:39
-
-
Save schalkneethling/82027b2eacdec7230fa9 to your computer and use it in GitHub Desktop.
Intercept and mock Ajax calls with Jasmine-Ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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'); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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