Skip to content

Instantly share code, notes, and snippets.

@trevmex
Created June 28, 2011 15:42
Show Gist options
  • Save trevmex/1051423 to your computer and use it in GitHub Desktop.
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.
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