Skip to content

Commit

Permalink
Add null check before rejecting BaseLoader.lastDeferred.
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Oct 22, 2024
1 parent a9ab351 commit e2c88f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/api/_loaders/_base-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,12 @@ class BaseLoader extends EventEmitter {

//prevent unhandled rejection.
node.deferred.promise.catch(err => {
BaseLoader.lastDeferred.reject(err);
if (BaseLoader.lastDeferred) {
// TODO: check in what cases BaseLoader.lastDeferred could be set to null
// in between the execution of the test.
// issue: #4265; hint: could have something to do with custom commands.
BaseLoader.lastDeferred.reject(err);
}
});

if (!this.module?.returnFn) {
Expand Down
7 changes: 5 additions & 2 deletions lib/api/_loaders/assertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AssertionLoader extends BaseCommandLoader {

static validateAssertClass(instance) {
Object.keys(AssertionLoader.interfaceMethods).forEach(method => {
let type = AssertionLoader.interfaceMethods[method];
const type = AssertionLoader.interfaceMethods[method];
if (!BaseCommandLoader.isTypeImplemented(instance, method, type)) {
const methodTypes = method.split('|').map(name => `"${name}"`);

Expand Down Expand Up @@ -113,7 +113,10 @@ class AssertionLoader extends BaseCommandLoader {

// prevent unhandledRejection errors
node.deferred.promise.catch(err => {
return AssertionLoader.lastDeferred.reject(err);
// null check, as done for BaseLoader.lastDeferred as well.
if (AssertionLoader.lastDeferred) {
return AssertionLoader.lastDeferred.reject(err);
}
});

return node.deferred.promise;
Expand Down

0 comments on commit e2c88f5

Please sign in to comment.