Created
May 16, 2015 01:06
-
-
Save lamchau/554e5f53e52ff7defabe to your computer and use it in GitHub Desktop.
sinon + ic.ajax
This file contains hidden or 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
function fakeServer(method, url, response) { | |
response = response || { | |
"data": "default" | |
}; | |
var server = sinon.fakeServer.create(), | |
// force a server pass through to enable response delays | |
forceServer = sinon.stub(App, "isApiEndpoint").returns(false), | |
// ic.ajax will always do an internal lookup before passing it on | |
// to $.ajax, so to ensure we are able to bypass without destroying | |
// a defined fixture we need to stub it | |
bypassLookup = sinon.stub(ic.ajax, "lookupFixture").returns(false); | |
server.restore = function() { | |
forceServer.restore(); | |
bypassLookup.restore(); | |
sinon.fakeServer.restore.call(server); | |
}; | |
server.respondWith(method, url, [200, { | |
"Content-Type": "application/json" | |
}, | |
JSON.stringify(response) | |
]); | |
server.autoRespond = true; | |
return server; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment