From d3ee2fc28dfadb7bcaf3bb10c6fe72abcba91051 Mon Sep 17 00:00:00 2001 From: Glenn Date: Wed, 15 Mar 2023 15:39:34 +0100 Subject: [PATCH] Added an _executeAsync method for async validated method testing --- validated-method.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/validated-method.js b/validated-method.js index 9ed4ad1..7042379 100644 --- a/validated-method.js +++ b/validated-method.js @@ -140,6 +140,23 @@ perhaps you meant to throw an error?`); return this.run.bind(methodInvocation)(args); } + + _executeAsync(methodInvocation = {}, args) { + //Add `this.name` to reference the Method name + methodInvocation.name = this.name; + + try { + const validateResult = this.validate.bind(methodInvocation)(args); + + if (typeof validateResult !== 'undefined') { + throw new Error('Returning from validate doesn\'t do anything; Perhaps you meant to throw an error?'); + } + + return this.run.bind(methodInvocation)(args); + } catch (err) { + return Promise.reject(err); + } + } }; // Mixins get a chance to transform the arguments before they are passed to the actual Method