Skip to content

Instantly share code, notes, and snippets.

@wtarr
Last active December 21, 2015 01:59
Show Gist options
  • Save wtarr/6231620 to your computer and use it in GitHub Desktop.
Save wtarr/6231620 to your computer and use it in GitHub Desktop.
Mockjax test: All calls to the server will be intercepted and replaced with the mockjax response text. Output will be MOCKJAX!!!! x 3
$(document).ready( function() {
$.mockjax({
// This should trigger a success and use my data
// as oppose to the data received from server
url: "http://localhost:8000/",
responseTime: 10,
dataType: 'text/json',
responseText: { "name" : "MOCKJAX!!!!" }
});
$.getJSON('http://localhost:8000/').success(function (data) {
// Running local test server is set to respond with { "name" : "PYTHONSERVER" }
doSomethingWithData(data)
});
$.getJSON('http://localhost:8000/').success(function (data) {
// Running local test server is set to respond with { "name" : "PYTHONSERVER" }
doSomethingWithData(data)
});
$.getJSON('http://localhost:8000/').success(function (data) {
// Running local test server is set to respond with { "name" : "PYTHONSERVER" }
doSomethingWithData(data)
});
function doSomethingWithData(data)
{
console.log(data['name']);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment