From 980162307830373b8a94440bf7b55af9e10ab998 Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Fri, 24 Aug 2018 12:20:07 +0530 Subject: [PATCH] [refactor] assertPromise --- src/lib/assertPromise.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib/assertPromise.js b/src/lib/assertPromise.js index c877879..2676309 100644 --- a/src/lib/assertPromise.js +++ b/src/lib/assertPromise.js @@ -1,9 +1,16 @@ const { isPromise } = require('../util'); -const _assertPromise = (bool, assertion) => { +const createRejectionStatement = (statement, ...args) => + Promise.reject(statement ? statement(...args) : ''); + +const _assertPromise = (bool, statementTuple) => { + const [ statement, ...args ] = statementTuple; if(isPromise(bool)) - return bool.catch(() => Promise.reject(assertion)); - return bool ? Promise.resolve() : Promise.reject(assertion); + return bool.catch(() => + createRejectionStatement(statement, ...args)); + return bool + ? Promise.resolve() + : createRejectionStatement(statement, ...args); }; module.exports = _assertPromise;