Skip to content

Commit

Permalink
fix an issue thanks to failing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Oct 20, 2024
1 parent 22cd2c9 commit ffc2e34
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
19 changes: 12 additions & 7 deletions lib/api/web-element/assert/element-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions lib/api/web-element/assert/value-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ffc2e34

Please sign in to comment.