Created
May 23, 2018 20:36
-
-
Save merecarvill/266add5b49d0b0711e0ace140ef3d180 to your computer and use it in GitHub Desktop.
jasmine vs sinon
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
it("first test", () => { | |
console.log("first test") | |
spyOn($, "ajax") | |
}) | |
it("second test", () => { | |
console.log("second test") | |
console.log($.ajax.calls) | |
}) | |
// $.ajax.calls is undefined in the second test | |
// if it were spied on, then it would be a CallTracker object | |
it("first test", () => { | |
console.log("first test") | |
const fakeServer = sinon.fakeServer.create() | |
fakeServer.respondWith([505, {}, ""]) | |
fakeServer.autoRespond = true | |
}) | |
it("second test", () => { | |
console.log("second test") | |
$.ajax("foo", {complete: (response) => console.log(response.status)}) | |
}) | |
// response.status is 505 in the second test, would be a 404 if an actual request were made |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment