Skip to content

Commit

Permalink
Add code comments for the recent assertions fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Oct 22, 2024
1 parent a3f3181 commit a9ab351
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/api/web-element/assert/element-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class ScopedElementAssertions {
}

assert(callback) {
// The below promise is returned to the test case by the assertion, so
// it should fail in case the actual assertion (callback) fails. In case
// of a sync test, the actual assertion would never fail, so we always
// resolve the promise.
const assertPromise = new Promise((resolve, reject) => {
const assert = this.nightwatchInstance.api.assert;

Expand All @@ -26,7 +30,7 @@ class ScopedElementAssertions {
});

// prevent unhandledRejection errors, while also making sure
// that the exception passes to the actual test case.
// that the exception/failure passes to the actual test case.
assertPromise.catch(() => {});

return assertPromise;
Expand Down
6 changes: 5 additions & 1 deletion lib/api/web-element/assert/value-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module.exports.create = function createAssertions(scopedValue, {negated, nightwa
}

_assert(callback) {
// The below promise is returned to the test case by the assertion, so
// it should fail in case the actual assertion (callback) fails. In case
// of a sync test, the actual assertion would never fail, so we always
// resolve the promise.
const assertPromise = new Promise((resolve, reject) => {
const assert = nightwatchInstance.api.assert;
const callbackResult = callback(this.negated ? assert.not : assert, this.scopedValue.value);
Expand All @@ -26,7 +30,7 @@ module.exports.create = function createAssertions(scopedValue, {negated, nightwa
});

// prevent unhandledRejection errors, while also making sure
// that the exception passes to the actual test case.
// that the exception/failure passes to the actual test case.
assertPromise.catch((err) => {});

return assertPromise;
Expand Down

0 comments on commit a9ab351

Please sign in to comment.