tests: Teach `waitFor()` to reject if the predicate throws
parent
262eb9af60
commit
8016bd225f
|
@ -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(){
|
||||
|
|
|
@ -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(){
|
||||
|
|
Loading…
Reference in New Issue