According to the Jasmine documentation, a mock can be created like this:
jasmine.createSpyObj(someObject, ['method1', 'method2', ... ]);
How do you stub one of these methods? For example, if you want to test what happens when a method throws an exception, how would you do that?
You have to chain
method1,method2as EricG commented, but not withandCallThrough()(orand.callThrough()in version 2.0). It will delegate to real implementation.In this case you need to chain with
and.callFake()and pass the function you want to be called (can throw exception or whatever you want):And then you can verify: