Skip to content

Instantly share code, notes, and snippets.

@jiverson
Forked from trevmex/jasmine.nested_spies.spec.js
Created December 23, 2013 17:00
Show Gist options
  • Save jiverson/8100614 to your computer and use it in GitHub Desktop.
Save jiverson/8100614 to your computer and use it in GitHub Desktop.
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