From 8dca4cb16fb89051e8f6b216350af98a4b2e79af Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sat, 13 Feb 2021 00:00:28 -0500 Subject: [PATCH] tests: Give `helper.waitFor()` timeout errors a useful stack trace --- src/tests/frontend/helper.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tests/frontend/helper.js b/src/tests/frontend/helper.js index 8fbc28d0f..eaa57fb89 100644 --- a/src/tests/frontend/helper.js +++ b/src/tests/frontend/helper.js @@ -198,6 +198,10 @@ const helper = {}; }; helper.waitFor = (conditionFunc, timeoutTime = 1900, intervalTime = 10) => { + // Create an Error object to use if the condition is never satisfied. This is created here so + // that the Error has a useful stack trace associated with it. + const timeoutError = + new Error(`waitFor condition never became true ${conditionFunc.toString()}`); const deferred = new $.Deferred(); const _fail = deferred.fail.bind(deferred); @@ -222,11 +226,10 @@ const helper = {}; const timeout = setTimeout(() => { clearInterval(intervalCheck); - const error = new Error(`wait for condition never became true ${conditionFunc.toString()}`); - deferred.reject(error); + deferred.reject(timeoutError); if (!listenForFail) { - throw error; + throw timeoutError; } }, timeoutTime);