In Jasmine, how do I dive to spy on a method?

I would like to omit the function in addition to spying on it in Jasmine. How can i do this?

var o = { foo: function(){} };
var spy = spyOn(o, 'foo')
  .andStubWith(function() { console.log('foo'); }); // This is pseudocode - is there a real equivalent?

The reason I don't want to just overwrite the function in my test is because IIUC, Jasmine will cancel any spyware after each test.

+4
source share
1 answer

See http://jasmine.imtqy.com/2.0/introduction.html#section-Spies:_and.callFake

spyOn(o, "foo").and.callFake(function() {
  console.log('foo')
  return 1001;
});
+3
source

All Articles