tests: Accept async condition functions for `helper.waitFor()`

pull/4770/head
Richard Hansen 2021-02-13 00:02:25 -05:00 committed by John McLear
parent 8dca4cb16f
commit 09e9c36098
2 changed files with 15 additions and 2 deletions

View File

@ -211,9 +211,9 @@ const helper = {};
return _fail(...args);
};
const check = () => {
const check = async () => {
try {
if (!conditionFunc()) return;
if (!await conditionFunc()) return;
deferred.resolve();
} catch (err) {
deferred.reject(err);

View File

@ -210,6 +210,19 @@ describe('the test helper', function () {
await helper.waitFor(() => true, 0);
});
});
it('accepts async functions', async function () {
await helper.waitFor(async () => true).fail(() => {});
// Make sure it checks the truthiness of the Promise's resolved value, not the truthiness of
// the Promise itself (a Promise is always truthy).
let ok = false;
try {
await helper.waitFor(async () => false, 0).fail(() => {});
} catch (err) {
ok = true;
}
expect(ok).to.be(true);
});
});
describe('the waitForPromise method', function () {