tests: Give `helper.waitFor()` timeout errors a useful stack trace

pull/4770/head
Richard Hansen 2021-02-13 00:00:28 -05:00 committed by John McLear
parent 71c1899164
commit 8dca4cb16f
1 changed files with 6 additions and 3 deletions

View File

@ -198,6 +198,10 @@ const helper = {};
}; };
helper.waitFor = (conditionFunc, timeoutTime = 1900, intervalTime = 10) => { 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 deferred = new $.Deferred();
const _fail = deferred.fail.bind(deferred); const _fail = deferred.fail.bind(deferred);
@ -222,11 +226,10 @@ const helper = {};
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
clearInterval(intervalCheck); clearInterval(intervalCheck);
const error = new Error(`wait for condition never became true ${conditionFunc.toString()}`); deferred.reject(timeoutError);
deferred.reject(error);
if (!listenForFail) { if (!listenForFail) {
throw error; throw timeoutError;
} }
}, timeoutTime); }, timeoutTime);