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

React Testing lesson: Recommend setup functions over beforeEach #29459

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Ghoulayush
Copy link

…Testing

Because

The current lesson suggests using beforeEach in Vitest for rendering components multiple times in tests. However, React Testing Library (RTL) discourages this practice in favor of using a custom setup function. This PR updates the lesson to align with best practices by recommending setup functions instead of beforeEach .

This PR

  • Replaces the sentence:
    "For a lot of tests for a component, the beforeEach Vitest function could prove handy."
    with
    "For a lot of tests for a component, a custom setup function could prove handy."
  • Ensures consistency with the RTL documentation and the following lesson.

Issue

Closes #29381

Additional Information

The change aligns with React Testing Library’s official guidance, which discourages rendering components inside beforeEach and recommends using a setup function instead.

Pull Request Requirements

  • I have thoroughly read and understand The Odin Project curriculum contributing guide
  • The title of this PR follows the location of change: brief description of change format, e.g. Intro to HTML and CSS lesson: Fix link text
  • The Because section summarizes the reason for this PR
  • The This PR section has a bullet point list describing the changes in this PR
  • If this PR addresses an open issue, it is linked in the Issue section
  • If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • If any lesson files are included in this PR, they follow the Layout Style Guide

@github-actions github-actions bot added the Content: React Involves the React course label Feb 26, 2025
@Ghoulayush
Copy link
Author

Ghoulayush commented Feb 26, 2025

Hey @01zulfi , I’ve submitted the PR for #29381. Let me know if any changes are needed. Thanks! 😊

@Ghoulayush
Copy link
Author

@gingkapls Thanks for catching that! I've reverted the unintended changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content: React Involves the React course
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduction To React Testing: Changes to the suggestion of calling render in beforeEach
2 participants