Skip to content

Conversation

@9aoy
Copy link
Contributor

@9aoy 9aoy commented Sep 29, 2025

Summary

The return functions of the beforeEach and beforeAll hooks in Rstest are used to perform cleaning work after testing.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings September 29, 2025 08:18
@netlify
Copy link

netlify bot commented Sep 29, 2025

Deploy Preview for rstest-dev ready!

Name Link
🔨 Latest commit 10f55c2
🔍 Latest deploy log https://app.netlify.com/projects/rstest-dev/deploys/68da40c4e997130008a6b246
😎 Deploy Preview https://deploy-preview-607--rstest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR documents a feature in Rstest where beforeEach and beforeAll hooks can return cleanup functions that automatically run after tests complete. The documentation is added to both English and Chinese versions of the migration guide and API reference.

  • Documents return function capabilities for beforeEach/beforeAll hooks
  • Provides code examples showing cleanup pattern implementation
  • Updates both migration guide and API documentation

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
website/docs/zh/guide/migration/jest.mdx Adds Chinese documentation for hook return functions in Jest migration guide
website/docs/zh/api/test-api/hooks.mdx Adds Chinese API documentation with examples for beforeAll and beforeEach return functions
website/docs/en/guide/migration/jest.mdx Adds English documentation for hook return functions in Jest migration guide
website/docs/en/api/test-api/hooks.mdx Adds English API documentation with examples for beforeAll and beforeEach return functions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


```diff
- beforeEach(() => doSomething());
+ beforeEach(() => { doSomething() });
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The migration example doesn't clearly demonstrate the cleanup function feature being documented. The diff only shows adding braces around doSomething() without showing how to return a cleanup function. Consider showing an example that actually returns a cleanup function to illustrate the feature.

Suggested change
+ beforeEach(() => { doSomething() });
+ beforeEach(() => {
+ doSomething();
+ return () => cleanupSomething();
+ });

Copilot uses AI. Check for mistakes.

```diff
- beforeEach(() => doSomething());
+ beforeEach(() => { doSomething() });
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

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

The migration example doesn't clearly demonstrate the cleanup function feature being documented. The diff only shows adding braces around doSomething() without showing how to return a cleanup function. Consider showing an example that actually returns a cleanup function to illustrate the feature.

Suggested change
+ beforeEach(() => { doSomething() });
- afterEach(() => cleanupSomething());
+ beforeEach(() => {
+ doSomething();
+ return () => cleanupSomething();
+ });

Copilot uses AI. Check for mistakes.
@9aoy 9aoy merged commit 6e4430b into main Sep 29, 2025
17 checks passed
@9aoy 9aoy deleted the docs/hook-returns branch September 29, 2025 08:25
@9aoy 9aoy mentioned this pull request Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants