diff --git a/dist/amd/wait.js b/dist/amd/wait.js index 1c8f1d2..4c661b9 100644 --- a/dist/amd/wait.js +++ b/dist/amd/wait.js @@ -32,10 +32,12 @@ define(["require", "exports"], function (require, exports) { } return new Promise(function (rs) { return setTimeout(rs, options.interval); }).then(wait); } + // We generate the error here to capture the stack trace, but we will only throw it if it times out + var timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed'); return Promise.race([ new Promise(function (_, rj) { return setTimeout(function () { timedOut = true; - rj(new Error(options.present ? 'Element not found' : 'Element not removed')); + rj(timeoutError); }, options.timeout); }), wait() ]); diff --git a/dist/commonjs/wait.js b/dist/commonjs/wait.js index 68616d8..1b6b957 100644 --- a/dist/commonjs/wait.js +++ b/dist/commonjs/wait.js @@ -31,10 +31,12 @@ function waitFor(getter, options) { } return new Promise(function (rs) { return setTimeout(rs, options.interval); }).then(wait); } + // We generate the error here to capture the stack trace, but we will only throw it if it times out + var timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed'); return Promise.race([ new Promise(function (_, rj) { return setTimeout(function () { timedOut = true; - rj(new Error(options.present ? 'Element not found' : 'Element not removed')); + rj(timeoutError); }, options.timeout); }), wait() ]); diff --git a/dist/es2015/wait.js b/dist/es2015/wait.js index 8f807f1..fdad4e7 100644 --- a/dist/es2015/wait.js +++ b/dist/es2015/wait.js @@ -20,10 +20,12 @@ export function waitFor(getter, options = { present: true, interval: 50, timeout } return new Promise(rs => setTimeout(rs, options.interval)).then(wait); } + // We generate the error here to capture the stack trace, but we will only throw it if it times out + const timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed'); return Promise.race([ new Promise((_, rj) => setTimeout(() => { timedOut = true; - rj(new Error(options.present ? 'Element not found' : 'Element not removed')); + rj(timeoutError); }, options.timeout)), wait() ]); diff --git a/dist/es2017/wait.js b/dist/es2017/wait.js index 8f807f1..fdad4e7 100644 --- a/dist/es2017/wait.js +++ b/dist/es2017/wait.js @@ -20,10 +20,12 @@ export function waitFor(getter, options = { present: true, interval: 50, timeout } return new Promise(rs => setTimeout(rs, options.interval)).then(wait); } + // We generate the error here to capture the stack trace, but we will only throw it if it times out + const timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed'); return Promise.race([ new Promise((_, rj) => setTimeout(() => { timedOut = true; - rj(new Error(options.present ? 'Element not found' : 'Element not removed')); + rj(timeoutError); }, options.timeout)), wait() ]); diff --git a/dist/native-modules/wait.js b/dist/native-modules/wait.js index 5d81447..daa747a 100644 --- a/dist/native-modules/wait.js +++ b/dist/native-modules/wait.js @@ -29,10 +29,12 @@ export function waitFor(getter, options) { } return new Promise(function (rs) { return setTimeout(rs, options.interval); }).then(wait); } + // We generate the error here to capture the stack trace, but we will only throw it if it times out + var timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed'); return Promise.race([ new Promise(function (_, rj) { return setTimeout(function () { timedOut = true; - rj(new Error(options.present ? 'Element not found' : 'Element not removed')); + rj(timeoutError); }, options.timeout); }), wait() ]); diff --git a/dist/system/wait.js b/dist/system/wait.js index 85fa35c..fd5a15b 100644 --- a/dist/system/wait.js +++ b/dist/system/wait.js @@ -32,10 +32,12 @@ System.register([], function (exports_1, context_1) { } return new Promise(function (rs) { return setTimeout(rs, options.interval); }).then(wait); } + // We generate the error here to capture the stack trace, but we will only throw it if it times out + var timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed'); return Promise.race([ new Promise(function (_, rj) { return setTimeout(function () { timedOut = true; - rj(new Error(options.present ? 'Element not found' : 'Element not removed')); + rj(timeoutError); }, options.timeout); }), wait() ]); diff --git a/src/wait.ts b/src/wait.ts index b2ba116..233ab3c 100644 --- a/src/wait.ts +++ b/src/wait.ts @@ -34,11 +34,14 @@ export function waitFor(getter: () => T, options: { return new Promise(rs => setTimeout(rs, options.interval)).then(wait); } + // We generate the error here to capture the stack trace, but we will only throw it if it times out + const timeoutError = new Error(options.present ? 'Element not found' : 'Element not removed'); + return Promise.race([ new Promise( (_, rj) => setTimeout(() => { timedOut = true; - rj(new Error(options.present ? 'Element not found' : 'Element not removed')); + rj(timeoutError); }, options.timeout) ), wait()