From 09e9c36098fc240cba91050c49a6696a6ced027a Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sat, 13 Feb 2021 00:02:25 -0500 Subject: [PATCH] tests: Accept async condition functions for `helper.waitFor()` --- src/tests/frontend/helper.js | 4 ++-- src/tests/frontend/specs/helper.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/tests/frontend/helper.js b/src/tests/frontend/helper.js index eaa57fb89..4dd7f22ac 100644 --- a/src/tests/frontend/helper.js +++ b/src/tests/frontend/helper.js @@ -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); diff --git a/src/tests/frontend/specs/helper.js b/src/tests/frontend/specs/helper.js index cb72fcf7a..fdd896ea9 100644 --- a/src/tests/frontend/specs/helper.js +++ b/src/tests/frontend/specs/helper.js @@ -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 () {