Skip to content

Instantly share code, notes, and snippets.

@chrisjpowers
Created November 3, 2011 18:43
Show Gist options
  • Save chrisjpowers/1337391 to your computer and use it in GitHub Desktop.
Save chrisjpowers/1337391 to your computer and use it in GitHub Desktop.
var Conundrum = {
doIt: function() {return "did it"; },
doItCopy: function() {return this.doIt(); }
};
describe('conundrum',function(){
describe("faking actual method", function() {
beforeEach(function() {
spyOn(Conundrum, "doIt").andReturn("fake");
});
it("fakes both calls", function() {
expect(Conundrum.doIt()).toEqual("fake");
expect(Conundrum.doItCopy()).toEqual("fake");
});
});
describe("faking the reference", function() {
beforeEach(function() {
spyOn(Conundrum, "doItCopy").andReturn("fake");
});
it("only fakes the call to the reference", function() {
expect(Conundrum.doIt()).toEqual("did it");
expect(Conundrum.doItCopy()).toEqual("fake");
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment