From 9931c3c83fc75d3695098e28f27dffa128b39747 Mon Sep 17 00:00:00 2001 From: Alex J Burke Date: Mon, 4 Apr 2016 14:39:25 +0100 Subject: [PATCH] Attach a stack trace to the it() block promise error generated if present. --- lib/notifyPendingPromise.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/notifyPendingPromise.js b/lib/notifyPendingPromise.js index f7884dc7c..735f43cf4 100644 --- a/lib/notifyPendingPromise.js +++ b/lib/notifyPendingPromise.js @@ -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) { var displayName; if (this.currentTest) { // mocha @@ -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) { + error.message += '\n\n' + pendingPromise.trace.stack; + } } pendingPromisesForTheCurrentTest = []; if (error && testPassed) {