Browse Source

[refactor] assertPromise

0.7.0-breaking-rewrite
Muthu Kumar 6 years ago
parent
commit
9801623078
  1. 13
      src/lib/assertPromise.js

13
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;

Loading…
Cancel
Save