Created
June 28, 2011 15:42
-
-
Save trevmex/1051423 to your computer and use it in GitHub Desktop.
Nesiting spies to see if a callback in a deep nest has worked.
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 nestedCallbacks(callback) { | |
console.log("start"); | |
firstNest(function () { | |
secondNest(function () { | |
callback("test"); | |
}); | |
}); | |
} | |
function firstNest(callback) { | |
console.log("in first"); | |
// Do some AJAX calls, then call callback later | |
callback(); | |
} | |
function secondNest(callback) { | |
console.log("in second"); | |
// Do some AJAX calls, then call callback later | |
callback(); | |
} | |
describe("nested spies", function () { | |
it("calls a nested callback function with true", function () { | |
console.log("in test"); | |
var callback = jasmine.createSpy(); | |
spyOn(window, "firstNest").andCallFake(function (callback1) {callback1();}); | |
spyOn(window, "secondNest").andCallFake(function (callback2) {callback2();}); | |
nestedCallbacks(callback); | |
expect(callback).toHaveBeenCalledWith("test"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment