From ffc2e34080fe6434567d0308c2eed1203e344362 Mon Sep 17 00:00:00 2001 From: Priyansh Garg Date: Mon, 21 Oct 2024 03:50:54 +0530 Subject: [PATCH] fix an issue thanks to failing tests. --- .../web-element/assert/element-assertions.js | 19 ++++++++++------- .../web-element/assert/value-assertions.js | 21 ++++++++++++------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/api/web-element/assert/element-assertions.js b/lib/api/web-element/assert/element-assertions.js index df9295042..3fe999212 100644 --- a/lib/api/web-element/assert/element-assertions.js +++ b/lib/api/web-element/assert/element-assertions.js @@ -11,13 +11,18 @@ class ScopedElementAssertions { const assertPromise = new Promise((resolve, reject) => { const assert = this.nightwatchInstance.api.assert; - callback(this.negated ? assert.not : assert, this.scopedElement.webElement) - .then(() => { - resolve(this.scopedElement); - }) - .catch(err => { - reject(err); - }); + const callbackResult = callback(this.negated ? assert.not : assert, this.scopedElement.webElement); + if (callbackResult instanceof Promise) { + callbackResult + .then(() => { + resolve(this.scopedElement); + }) + .catch(err => { + reject(err); + }); + } else { + resolve(this.scopedElement); + } }); // prevent unhandledRejection errors, while also making sure diff --git a/lib/api/web-element/assert/value-assertions.js b/lib/api/web-element/assert/value-assertions.js index d59f70a36..d243bb441 100644 --- a/lib/api/web-element/assert/value-assertions.js +++ b/lib/api/web-element/assert/value-assertions.js @@ -11,18 +11,23 @@ module.exports.create = function createAssertions(scopedValue, {negated, nightwa _assert(callback) { const assertPromise = new Promise((resolve, reject) => { const assert = nightwatchInstance.api.assert; - callback(this.negated ? assert.not : assert, this.scopedValue.value) - .then(() => { - resolve(this.scopedValue); - }) - .catch(err => { - reject(err); - }); + const callbackResult = callback(this.negated ? assert.not : assert, this.scopedValue.value); + if (callbackResult instanceof Promise) { + callbackResult + .then(() => { + resolve(this.scopedValue); + }) + .catch(err => { + reject(err); + }); + } else { + resolve(this.scopedValue); + } }); // prevent unhandledRejection errors, while also making sure // that the exception passes to the actual test case. - assertPromise.catch(() => {}); + assertPromise.catch((err) => {}); return assertPromise; }