Created
September 6, 2017 09:21
-
-
Save glyons/70a42a513fc434d1b4a9178e3b0aeb8f to your computer and use it in GitHub Desktop.
Javascript QUnit - Fake GET Test using SinonJS
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
QUnit.test("Javascript QUnit - Fake GET Test using SinonJS", function (assert) { | |
var url = "http://someurltofake"; | |
var xhr = sinon.useFakeXMLHttpRequest(); | |
var requests = sinon.requests = []; | |
xhr.onCreate = function (request) { | |
requests.push(request); | |
}; | |
var callback = sinon.spy(); | |
$.get(url).success(callback); | |
assert.equal(sinon.requests.length, 1); | |
assert.equal(sinon.requests[0].url, url); | |
requests[0].respond(200, { "Content-Type": "application/json" }, "[]"); | |
assert.ok(callback.called); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment