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

Attach a stack trace to the it() block promise error generated if pre… #302

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
12 changes: 11 additions & 1 deletion lib/notifyPendingPromise.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ function registerAfterEachHook() {
afterEach(function () {
var error;
var testPassed = true;
if (pendingPromisesForTheCurrentTest.some(function (promise) {return promise.isPending();})) {
var pendingPromise = null;
pendingPromisesForTheCurrentTest.some(function (promise) {
if (promise.isPending()) {
pendingPromise = promise;
return true;
}
});
if (pendingPromise) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if multiple promises are pending?

var displayName;
if (this.currentTest) {
// mocha
Expand All @@ -34,6 +41,9 @@ function registerAfterEachHook() {
displayName = currentSpec.fullName;
}
error = new Error(displayName + ': You have created a promise that was not returned from the it block');
if (pendingPromise.trace && pendingPromise.trace.stack) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it pendingPromise._trace?

error.message += '\n\n' + pendingPromise.trace.stack;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it might be nice to apply UnexpectedError's stack trimming here?

}
}
pendingPromisesForTheCurrentTest = [];
if (error && testPassed) {
Expand Down