You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: lessons/07-testing/A-vitest.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ Let's go add an npm script. In your package.json.
46
46
47
47
This command lets you run Jest in an interactive mode where it will re-run tests selectively as you save them. This lets you get instant feedback if your test is working or not. This is probably my favorite feature of Vitest.
48
48
49
-
Okay, one little configuration to add to your vite.config.js.
49
+
Okay, one little configuration to add to your `vite.config.js`.
Copy file name to clipboardexpand all lines: lessons/07-testing/D-testing-custom-hooks.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ keywords:
12
12
- API testing
13
13
---
14
14
15
-
Let's say we needs tests for our custom hook, usePizzaOfTheDay. Testing custom hooks is a bit of a trick because they are inherently tied to the internal workings of React: they can't be called outside of a component. So how we do we get around that? We fake a component! Make a file called usePizzaOfTheDay.test.jsx in our `__tests__` directory.
15
+
Let's say we needs tests for our custom hook, usePizzaOfTheDay. Testing custom hooks is a bit of a trick because they are inherently tied to the internal workings of React: they can't be called outside of a component. So how we do we get around that? We fake a component! Make a file called `usePizzaOfTheDay.test.jsx` in our `__tests__` directory.
Copy file name to clipboardexpand all lines: lessons/07-testing/F-coverage.md
+3-2
Original file line number
Diff line number
Diff line change
@@ -21,14 +21,15 @@ One last very cool trick that Vitest has built into it: [v8][v8]. v8 uses Chrome
21
21
Run the following
22
22
23
23
```bash
24
-
npm i -D @vitest/coverage-v8
24
+
npm i -D @vitest/coverage-v8@2.1.3
25
25
```
26
26
27
27
> You can also use [Istanbul][istanbul] if you want to. `npm i -D @vitest/coverage-istanbul` will get you the package. But I'd say v8 is the superior tool.
Copy file name to clipboardexpand all lines: lessons/07-testing/H-browser-tests.md
+41-2
Original file line number
Diff line number
Diff line change
@@ -72,7 +72,7 @@ This is a test-only config for Vite (and therefore Vitest.) Now if a test ends i
72
72
73
73
Snapshotting works in the browser so that one works okay. Anything using vitest-fetch-mock is Node.js only so for those we need to mark them as node. We're going to make a new Pizza file so let's leave that one. And our custom hook test mocks fetch so that one is Node only.
74
74
75
-
Okay, now create a Pizza.browser.test.jsx
75
+
Okay, now create a `Pizza.browser.test.jsx`
76
76
77
77
```javascript
78
78
import { render } from"vitest-browser-react";
@@ -103,7 +103,7 @@ Looks really similar, right? Alright, let's run it. `npm run test`. You should s
103
103
104
104
> It will likely prompt you to run a command like `npx playwright install`. You'll install local copies of browsers to able to run them super fast.
105
105
106
-
Cool, right? And really fast! Let's do one more. Let's make a Header.jsx test. We're going to test that the cart number is correct. Remember when Facebook notification numbers were always wrong? We're going to make sure that doesn't happen with our cart indicator. In your Header.jsx file:
106
+
Cool, right? And really fast! Let's do one more. Let's make a `Header.jsx` test. We're going to test that the cart number is correct. Remember when Facebook notification numbers were always wrong? We're going to make sure that doesn't happen with our cart indicator. In your Header.jsx file:
107
107
108
108
```javascript
109
109
data-testid="cart-number"// add to .nav-cart-number
@@ -165,6 +165,45 @@ We do have to bend over a bit backwards to make sure TanStack Router is happy, h
165
165
166
166
Again, these are early days for browser-based testing with Vite so proceed in your professional settings with caution. However the future is bright with Playwright!
167
167
168
+
> 🚨 NOTE: If you want to add code coverage back into the project, you'll need to use Istanbul since, at the time of this recording, this wasn't supported in React 19 with V8
169
+
170
+
First, you'll need to uninstall V8 and install Istanbul:
Copy file name to clipboardexpand all lines: lessons/08-whats-next/A-react-19.md
+2
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,8 @@ keywords:
15
15
16
16
## React 19
17
17
18
+
> 🚨 The rest of the course covers experimental features of React 19. If you want to try out these features without affecting your current project, we recommend using the `14-testing` project.
19
+
18
20
This course has been centered on version 18.3. The nice thing about React is that while they do make breaking changes, they are usually fairly intentional about it and do so sparingly. In other words, what you learned today will still be useful five years from now. You could take the version of the course I taught five years ago and still be pretty up to date on how to write React. In other words, despite the fact that React 19 is imminent (or perhaps even out by the time you read this), there's no need to panic. All the stuff they are adding will just complement what you have learned and not change it.
19
21
20
22
Do keep an eye out for version 6 of my Intermediate React course. We will cover a lot of the React 19 features in that course.
Copy file name to clipboardexpand all lines: lessons/08-whats-next/B-form-actions.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ mutationFn: function (formData) { // change to formData
42
42
43
43
That's it! It really is just a convenience function to make handling for submits even easier to do. There's nothing wrong with what we had either, and that will continue to work as-is too.
44
44
45
-
Let's go convert order.lazy.jsx too
45
+
Let's go convert `order.lazy.jsx` too
46
46
47
47
```javascript
48
48
// extract submission function from form
@@ -67,9 +67,9 @@ function addToCart(formData) {
67
67
68
68
Since it's on the server, we can now safely insert into our database, directly from inside our React component. React/Next.js will handle all the details of handling the execution of that on server. Pretty cool, right? We'll talk more about this in Intermediate React v6.
69
69
70
-
Let's do one more cool trick here. There's a new hook called `useFormData` that lets children components see if they're inside of a form being submitted without having to pass lots of data around.
70
+
Let's do one more cool trick here. There's a new hook called `useFormStatus` that lets children components see if they're inside of a form being submitted without having to pass lots of data around.
0 commit comments