new Spy()
Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks.
Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine expectation syntax. Spies can be
checked if they were called or not and what the calling params were.
Spies are torn down at the end of every spec.
Spies can be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. To check whether a variable contains a spy, please use jasmine.isSpy.
Spies can be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. To check whether a variable contains a spy, please use jasmine.isSpy.
- See:
-
- spyOn, jasmine.createSpy, jasmine.createSpyObj
Members
-
and :jasmine.SpyStrategy
-
Type:
- Since:
- 1.9.0
-
argsForCall
-
- Deprecated:
- Use spy.calls.allArgs instead
-
calls :jasmine.CallTracker
-
Type:
- Since:
- 1.9.0
-
mostRecentCall
-
- Deprecated:
- Use spy.calls.mostRecent instead
Methods
-
andCallFake(fakeFunc)
-
Calls an alternate implementation when a spy is called.
Parameters:
Name Type Description fakeFunc
function Method to be called - Deprecated:
- Use spy.and.callFake instead
-
andCallThrough()
-
Tells a spy to call through to the actual implemenatation.
- Deprecated:
- Use spy.and.callThrough instead
-
andReturn(value)
-
For setting the return value of a spy.
Parameters:
Name Type Description value
Object Value to be returned - Deprecated:
- Use spy.and.returnValue instead
-
andThrow(exceptionMsg)
-
For throwing an exception when a spy is called.
Parameters:
Name Type Description exceptionMsg
String Exception to be thrown - Deprecated:
- Use spy.and.throwError instead
-
reset()
-
Resets all of a spy's the tracking variables so that it can be used again.
- Deprecated:
- Use spy.calls.reset instead