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

Adding a check in onHookEnd to only call error function if it exists and is a function (fixes #482) #484

Closed
Closed
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
5 changes: 4 additions & 1 deletion packages/allure-mocha/src/MochaAllureReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export class MochaAllureReporter extends Mocha.reporters.Base {
}

private onHookEnd(hook: Mocha.Hook): void {
this.coreReporter.endHook(hook.error());
if(typeof(hook.error) === 'function')
this.coreReporter.endHook(hook.error());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we set default value for hook.error? Like just stub function to avoid additional conditions?
Or we can use optional chaining operator to reach the same result:

this.coreReporter.endHook(hook?.error?.());

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@epszaw I will give it a try later in the month when I get some more time. Thanks for the feedback.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @epszaw I just got back around to looking at this. It looks like we can close this pull request. I can see you added this change in this commit: cbb3426. Thanks for adding it in.

else
this.coreReporter.endHook();
}
}