diff --git a/lib/chai-as-promised.js b/lib/chai-as-promised.js index 0b84194..53f35ea 100644 --- a/lib/chai-as-promised.js +++ b/lib/chai-as-promised.js @@ -290,6 +290,7 @@ module.exports = (chai, utils) => { return assertion; } + const stack = new Error().stack; const derivedPromise = getBasePromise(assertion).then(value => { // Set up the environment for the asserter to actually run: `_obj` should be the fulfillment value, and // now that we have the value, we're no longer in "eventually" mode, so we won't run any of this code, @@ -299,7 +300,14 @@ module.exports = (chai, utils) => { return args ? module.exports.transformAsserterArgs(args) : args; }).then(newArgs => { - asserter.apply(assertion, newArgs); + try { + asserter.apply(assertion, newArgs); + } catch(e) { + let where = stack.split('\n').slice(1).find(line => line.includes("Context")); + where = where.match(/\((.+?)\)/)?.[1]; + e.stack += `\n ⚠️ ${where}`; + throw e; + } // Because asserters, for example `property`, can change the value of `_obj` (i.e. change the "object" // flag), we need to communicate this value change to subsequent chained asserters. Since we build a