Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add null check before rejecting BaseLoader.lastDeferred. #4278

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading