weaselpecker
Waterline Simple Mocking Library
Installation
npm install weaselpecker --save-dev
Quick Example
var weaselpecker = ;// Create a model mock instancevar ModelMock = weaselpecker;// Set results for find methodModelMock; ModelMock ;
Documentation
weaselpecker
Default available model methods
'hasJoin' 'join' 'create' 'find' 'findOne' 'update' 'destroy' 'count'
mock([options])
Creates a new instance of a mock model
Options
Array options.extraModelMethods
Array with custom methods to be attached to the mocked model
Example
var Model = weaselpecker;Model;Model;
setResults(str, arr)
Sets mock results for an specific model method call. Results are returned depending the order defined in the array. If there's only one result left it will always return that as result. If an Error
object is listed, it will be passed as an error.
Example
Model; //first call Model ;
arguments
- str: Name of the model method e.g 'find'
- arr: Array of mock results
clearResults()
Clears all mock results.
setErrors(str, arr)
Sets mock errors for an specific model method call. Results are returned depending the order defined in the array. If there's only one error left it will always return that as error.
Example
Model; //first call Model ;
arguments
- str: Name of the model method e.g 'find'
- arr: Array of mock errors
clearErrors()
Clears all mocked errors.