diff --git a/tests/frontend/helper.js b/tests/frontend/helper.js index b059f653c..c61a6213b 100644 --- a/tests/frontend/helper.js +++ b/tests/frontend/helper.js @@ -169,16 +169,14 @@ var helper = {}; }; var intervalCheck = setInterval(function(){ - var passed = false; - - passed = conditionFunc(); - - if(passed){ - clearInterval(intervalCheck); - clearTimeout(timeout); - + try { + if (!conditionFunc()) return; deferred.resolve(); + } catch (err) { + deferred.reject(err); } + clearInterval(intervalCheck); + clearTimeout(timeout); }, intervalTime); var timeout = setTimeout(function(){ diff --git a/tests/frontend/specs/helper.js b/tests/frontend/specs/helper.js index 1cb712a00..062b3f94d 100644 --- a/tests/frontend/specs/helper.js +++ b/tests/frontend/specs/helper.js @@ -155,6 +155,15 @@ describe("the test helper", function(){ }); }); + it('rejects if the predicate throws', async function() { + let err; + await helper.waitFor(() => { throw new Error('test exception'); }) + .fail(() => {}) // Suppress the redundant uncatchable exception. + .catch((e) => { err = e; }); + expect(err).to.be.an(Error); + expect(err.message).to.be('test exception'); + }); + describe("returns a deferred object", function(){ it("it calls done after success", function(done){ helper.waitFor(function(){