Skip to content

Instantly share code, notes, and snippets.

@merecarvill
Created May 23, 2018 20:36
Show Gist options
  • Save merecarvill/266add5b49d0b0711e0ace140ef3d180 to your computer and use it in GitHub Desktop.
Save merecarvill/266add5b49d0b0711e0ace140ef3d180 to your computer and use it in GitHub Desktop.
jasmine vs sinon
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