tests: Teach `waitFor()` to reject if the predicate throws

pull/4415/head
Richard Hansen 2020-10-13 21:57:19 -04:00 committed by John McLear
parent 262eb9af60
commit 8016bd225f
2 changed files with 15 additions and 8 deletions

View File

@ -169,16 +169,14 @@ var helper = {};
};
var intervalCheck = setInterval(function(){
var passed = false;
passed = conditionFunc();
if(passed){
try {
if (!conditionFunc()) return;
deferred.resolve();
} catch (err) {
deferred.reject(err);
}
clearInterval(intervalCheck);
clearTimeout(timeout);
deferred.resolve();
}
}, intervalTime);
var timeout = setTimeout(function(){

View File

@ -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(){