Skip to content

Commit 515697c

Browse files
committed
updates from QA
1 parent 67d6683 commit 515697c

File tree

7 files changed

+2246
-193
lines changed

7 files changed

+2246
-193
lines changed

lessons/07-testing/A-vitest.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Let's go add an npm script. In your package.json.
4646
4747
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.
4848

49-
Okay, one little configuration to add to your vite.config.js.
49+
Okay, one little configuration to add to your `vite.config.js`.
5050

5151
```javascript
5252
// add this to the config object

lessons/07-testing/D-testing-custom-hooks.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ keywords:
1212
- API testing
1313
---
1414

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.
1616

1717
```javascript
1818
import { expect, test, vi } from "vitest";

lessons/07-testing/F-coverage.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ One last very cool trick that Vitest has built into it: [v8][v8]. v8 uses Chrome
2121
Run the following
2222

2323
```bash
24-
npm i -D @vitest/coverage-v8
24+
npm i -D @vitest/coverage-v8@2.1.3
2525
```
2626

2727
> 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.
2828
29-
Now add this to your vite.config.js
29+
Now add this to your `vite.config.js`
3030

3131
```javascript
32+
// inside the test object
3233
coverage: {
3334
reporter: ["text", "json", "html"],
3435
},

lessons/07-testing/H-browser-tests.md

+41-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ This is a test-only config for Vite (and therefore Vitest.) Now if a test ends i
7272

7373
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.
7474

75-
Okay, now create a Pizza.browser.test.jsx
75+
Okay, now create a `Pizza.browser.test.jsx`
7676

7777
```javascript
7878
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
103103

104104
> 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.
105105
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:
107107

108108
```javascript
109109
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
165165

166166
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!
167167

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:
171+
172+
```bash
173+
npm uninstall @vitest/[email protected]
174+
npm install -D @vitest/istanbul
175+
```
176+
Then move the coverage configuration to the `vitest.workspace.js` file:
177+
178+
```javascript
179+
180+
export default defineWorkspace([
181+
{
182+
extends: "./vite.config.js",
183+
test: {
184+
// ...
185+
// add to the end of the happy-dom test object
186+
coverage: {
187+
provider: "istanbul"
188+
reporter: ["text", "json", "html"],
189+
},
190+
},
191+
},
192+
{
193+
extends: "./vite.config.js",
194+
test: {
195+
// ...
196+
// add to the end of the browser test object
197+
coverage: {
198+
reporter: ["text", "json", "html"],
199+
},
200+
},
201+
},
202+
]);
203+
```
204+
205+
206+
168207
> 🏁 [Click here to see the state of the project up until now: 14-testing][step]
169208
170209
[step]: https://github.com/btholt/citr-v9-project/tree/master/14-testing

lessons/08-whats-next/A-react-19.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ keywords:
1515

1616
## React 19
1717

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+
1820
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.
1921

2022
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.

lessons/08-whats-next/B-form-actions.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mutationFn: function (formData) { // change to formData
4242

4343
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.
4444

45-
Let's go convert order.lazy.jsx too
45+
Let's go convert `order.lazy.jsx` too
4646

4747
```javascript
4848
// extract submission function from form
@@ -67,9 +67,9 @@ function addToCart(formData) {
6767

6868
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.
6969

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.
7171

72-
In contact.lazy.jsx
72+
In `contact.lazy.jsx`
7373

7474
```javascript
7575
// at top

0 commit comments

Comments
 (0)