diff --git a/tests/frontend/specs/helper.js b/tests/frontend/specs/helper.js index fb8ee3ca1..9d0914013 100644 --- a/tests/frontend/specs/helper.js +++ b/tests/frontend/specs/helper.js @@ -216,49 +216,30 @@ describe("the test helper", function(){ }); describe('the waitForPromise method', function() { + it('returns a Promise', async function() { + expect(helper.waitForPromise(() => true)).to.be.a(Promise); + }); + it('takes a timeout and waits long enough', async function() { this.timeout(2000); - var startTime = Date.now(); - await helper.waitForPromise(function() { - return false; - }, 1500).catch(function() { - var duration = Date.now() - startTime; - expect(duration).to.be.greaterThan(1490); - }); + const startTime = Date.now(); + let rejected; + await helper.waitForPromise(() => false, 1500) + .catch(() => { rejected = true; }); + expect(rejected).to.be(true); + const duration = Date.now() - startTime; + expect(duration).to.be.greaterThan(1490); }); it('takes an interval and checks on every interval', async function() { this.timeout(4000); - var checks = 0; - await helper.waitForPromise(function() { - checks++; - return false; - }, 2000, 100).catch(function() { - expect(checks).to.be.greaterThan(15); - expect(checks).to.be.lessThan(21); - }); - }); - - describe('returns a Promise', function() { - it('calls then after success', async function() { - let called = false; - await helper.waitForPromise(function() { - return true; - }).then(function() { - called = true; - }); - expect(called).to.be(true); - }); - - it('calls catch on failure', async function() { - let called = false; - await helper.waitForPromise(function() { - return false; - },0).catch(function() { - called = true; - }); - expect(called).to.be(true); - }); + let checks = 0; + let rejected; + await helper.waitForPromise(() => { checks++; return false; }, 2000, 100) + .catch(() => { rejected = true; }); + expect(rejected).to.be(true); + expect(checks).to.be.greaterThan(15); + expect(checks).to.be.lessThan(21); }); });