diff --git a/soap-stub.js b/soap-stub.js index c9d3880a0..36000c133 100644 --- a/soap-stub.js +++ b/soap-stub.js @@ -20,6 +20,7 @@ var clientStubs = {}; */ module.exports = { createClient: createClient, + createErroringStub: createErroringStub, createRespondingStub: createRespondingStub, errOnCreateClient: false, getStub: getStub, @@ -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. + * + *
+ * myClientStub.someMethod.errorOnCall = createErroringStub(error); + * + * // elsewhere + * + * myClientStub.someMethod.errorOnCall(); + *+ * + * @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. * *
* myClientStub.someMethod.respondWithError = createRespondingStub(errorResponse);