Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show which line #276

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/chai-as-promised.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down