Skip to content

Commit 9931c3c

Browse files
committed
Attach a stack trace to the it() block promise error generated if present.
1 parent fc1ce8a commit 9931c3c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/notifyPendingPromise.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ function registerAfterEachHook() {
2323
afterEach(function () {
2424
var error;
2525
var testPassed = true;
26-
if (pendingPromisesForTheCurrentTest.some(function (promise) {return promise.isPending();})) {
26+
var pendingPromise = null;
27+
pendingPromisesForTheCurrentTest.some(function (promise) {
28+
if (promise.isPending()) {
29+
pendingPromise = promise;
30+
return true;
31+
}
32+
});
33+
if (pendingPromise) {
2734
var displayName;
2835
if (this.currentTest) {
2936
// mocha
@@ -34,6 +41,9 @@ function registerAfterEachHook() {
3441
displayName = currentSpec.fullName;
3542
}
3643
error = new Error(displayName + ': You have created a promise that was not returned from the it block');
44+
if (pendingPromise.trace && pendingPromise.trace.stack) {
45+
error.message += '\n\n' + pendingPromise.trace.stack;
46+
}
3747
}
3848
pendingPromisesForTheCurrentTest = [];
3949
if (error && testPassed) {

0 commit comments

Comments
 (0)