8000 React: Improve introduction to React Testing · Issue #29377 · TheOdinProject/curriculum · GitHub
[go: up one dir, main page]

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: Improve introduction to React Testing #29377

Open
2 of 3 tasks
hbar1st opened this issue Feb 4, 2025 · 1 comment
Open
2 of 3 tasks

React: Improve introduction to React Testing #29377

hbar1st opened this issue Feb 4, 2025 · 1 comment

Comments

@hbar1st
Copy link
hbar1st commented Feb 4, 2025

Checks

Describe your suggestion

The lesson called "Introduction To React Testing" is in dire need of an actual introductory paragraph that explains what is going on in the lesson. We start the lesson with an introduction that misses the main point of the lesson, which is that we're here to learn how to test the UI components that React creates. This is unlike how we used jest for example which we only explored in terms of testing the functions/classes/methods that we wrote that didn't directly deal with DOM manipulation/ui testing. So this is a big jump and requires a real introduction.
Without that introduction, we are thrown into the paragraph called "Our First Query" blind. We don't know what a query is yet, we don't know why we need it, we don't even understand the first 2 sentences of this section which are:

First, we’ll render the component using render. The API will return an object and we’ll use destructuring syntax to obtain a subset of the methods required.

To us, 'render' is what we just learned about in class components (well either that or it is a reference to the life cycle of a component in React which also doesn't fit contextually here). That's the only reference we have to rendering. So is that what we're doing here? And why does the first statement say "render the component" as if it is referring to some specific component that we should have been aware of? Shouldn't it say something more general like "To test a React component, we start by rendering it." Or something like that which is more general?

Then looking at the 2nd sentence we have even more mystery to unravel. It says "The API" as if we should know which API it means? (and no we don't know what it means as we haven't been told to read about an "API" in this lesson yet?) and then it says that "we'll use destructuring syntax" but there is no sign of any such syntax in the example provided immediately following this paragraph? Here's the full example:

// App.jsx

const App = () => <h1>Our First Test</h1>;

export default App;
// App.test.jsx

import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import App from "./App";

describe("App component", () => {
  it("renders correct heading", () => {
    render(<App />);
    expect(screen.getByRole("heading").textContent).toMatch(/our first test/i);
  });
});

So then we're left again wondering what we've missed...

As an introduction to React testing, this section needs a lot of work!
Thanks for your attention.

Path

Node / JS

Lesson Url

https://www.theodinproject.com/lessons/node-path-react-new-introduction-to-react-testing

(Optional) Discord Name

No response

(Optional) Additional Comments

Please do not think I opened this so I can personally get clarification on this lesson. I've already done so by asking on discord. I opened the issue because I think the lesson needs to be fixed so others can benefit.

@CouchofTomato
Copy link
Member

@TheOdinProject/react Can someone take a look please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0