Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions soap-stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var clientStubs = {};
*/
module.exports = {
createClient: createClient,
createErroringStub: createErroringStub,
createRespondingStub: createRespondingStub,
errOnCreateClient: false,
getStub: getStub,
Expand Down Expand Up @@ -59,8 +60,32 @@ function createClient(wsdlUrl, options, cb) {
}

/**
* Returns a method that calls all callbacks given to the method it is attached to.
* This allows you to trigger responses from your tests.
* Returns a method that calls all callbacks given to the method it is attached
* to with the given error.
*
* <pre>
* myClientStub.someMethod.errorOnCall = createErroringStub(error);
*
* // elsewhere
*
* myClientStub.someMethod.errorOnCall();
* </pre>
*
* @param {?} object anything
* @return {Function}
*/
function createErroringStub(err) {
return function() {
this.args.forEach(function(argSet) {
setTimeout(argSet[1].bind(null, err));
});
this.yields(err);
};
}

/**
* Returns a method that calls all callbacks given to the method it is attached
* to with the given response.
*
* <pre>
* myClientStub.someMethod.respondWithError = createRespondingStub(errorResponse);
Expand Down