expect-called
If you want to verify that a function was called in the way you expect.
Install
$ npm install expect-called
API
expectedCalled.control(object, functionName, [opts])
Creates a function wrapper for object[functionName], the wrapper function will register de parameters used to call the function (included this) and then calls de original function and returns the returned value.
Returns a control object
opts | type | use for |
---|---|---|
withThis | boolean | register this object in calls |
returns | Array | create a mock function that returns each of the elements in the list one by one |
mocks | Array of function | funcions to call instead original function. Each element of the array is called in each call with the same parámeters and returning the corresponding returned value |
control.call
Is the array property that contains each call to the function.
Each call generates a object with two properties {This: ..., args: [... ]}
control.stopControl()
Stops the control function.
expectedCalled.global
SYMBOL that represents the root object in control.call
Example
var expect = ; // needed for the example var expectCalled = ; var myModule= { return word+word; } { // function to TEST and to CONTROL // must call upper } ;
Notes
- Not usefull for local functions that do not belong to a object
- Not control de returned value but could specify the returned values (like a mock function)
- Call to control with the same function name twice without stopping the previous control could generate unexpected results.