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; }