Skip to content

Commit d865ac1

Browse files
committed
flow
1 parent 1957aa4 commit d865ac1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Breakpoints
22

3-
Placing a `debugger` statement anywhere in your code or test is not the only way to create a breakpoint. In fact, you might've noticed that putting the `debugger` in our test makes us _modify that test_!
3+
Placing a `debugger` statement anywhere in your code or test is not the only way to create a breakpoint. In fact, you might've noticed we have to _modify our test_ to add the `debugger` statement!
44

5-
That isn't nice. Instead, you can add a breakpoint through your IDE.
5+
That isn't ideal. You can add a breakpoint through your IDE instead:
66

77
1. Locate the line of code you want to set a breakpoint at;
88
1. Either click on the red circle on the gutter next to that line or right-click the gutter and select "Add a breakpoint":
@@ -11,7 +11,7 @@ That isn't nice. Instead, you can add a breakpoint through your IDE.
1111

1212
> 🦉 Note that adding a breakpoint on a line will pause the execution **before** that line runs, not after. If you want to pause after a certian action, put a breakpoint after it in the code.
1313
14-
👨‍💼 In this exercise, I will have a few tasks for you.
14+
👨‍💼 In this exercise, I have a few tasks for you:
1515

16-
1. Replace the `debugger` statements in the <InlineFile file="./src/tic-tac-toe-browser.test.tsx">`./src/`tic-tac-toe-browser.test.tsx`</InlineFile> with breakpoints set in your IDE. Run the tests in the debug mode to verify that breakpoints actually stop the test run where you want them to.
16+
1. Replace the `debugger` statements in the <InlineFile file="./src/tic-tac-toe-browser.test.tsx">`./src/`tic-tac-toe-browser.test.tsx`</InlineFile> with breakpoints set in your IDE. Run the tests in debug mode to verify that breakpoints actually stop the test run where you want them to.
1717
1. Complete the test case in <InlineFile file="./src/main-menu.browser.test.tsx">`./src/`main-menu.browser.test.tsx`</InlineFile>. This is a new component rendering a menu in our app. It looks simple enough but there's something odd about those active links... Once you finish the test, run it in the debug mode and try to see how you can use conditional breakpoints to get to the root cause of the issue.

exercises/04.debugging/03.solution.breakpoints/README.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,30 +133,30 @@ Received:
133133

134134
Looks like the current page link that gets rendered is the "Dashboard" link and not "Analytics". This demands some debugging.
135135

136-
Now, there's multiple ways you can approach debugging this. You can go through the source code or maybe inspect the DOM via the `debug()` method from `render()` or print all the active link elements. Any technique is a good technique if it helps you get to the bottom of the issue faster.
136+
Now, there are many ways you can approach debugging this. You can go through the source code or maybe inspect the DOM via the `debug()` method from `render()` or print all the active link elements. Any technique is good if it helps you get to the bottom of the issue faster.
137137

138-
To give you more tools for debugging, I will approach this issue differently. If I take a look above the printed error in the terminal, I can spot this line:
138+
To teach you more tools for debugging, I will approach this issue differently. If I take a look above the printed error in the terminal, I see this line:
139139

140140
```
141141
Failure screenshot:
142142
- src/__screenshots__/main-menu.browser.test.tsx/----1.png
143143
```
144144

145-
Vitest takes screenshots of the page for every failed test case so you have some visual clue as to what is going on. Let's take a look at that screenshot:
145+
Vitest takes screenshots of the page for every failed test case to give you a visual clue about what is going on. Let's take a look at that screenshot:
146146

147147
![A screenshot of the page with the main menu component rendered. It shows two menu links as active—dashboard and analytics.](/assets/04-03-test-screenshot.png)
148148

149-
Hah! Both "Dashboard" and "Analytics" are treated as currently active navigation link.
149+
Aha! Both "Dashboard" and "Analytics" are treated as currently active navigation links.
150150

151151
> 🦉 While it's not forbidden to have multiple `aria-current="page"` elements at the same time, it is generally advised by the [WAI-ARIA specification](https://w3c.github.io/aria/#aria-current) to "only mark **one** element as current".
152152
153-
The fact that the "Analytics" menu item is marked as current is correct, that's what I expect. It's the "Dashboard" that's likely off here. It would be great to stop the time and look around when that menu item is getting rendered.
153+
The fact that the "Analytics" menu item is marked as current is correct, that's what I expect. It's the "Dashboard" that's likely wrong here. It would be great to stop the time and look around when that menu item is getting rendered.
154154

155155
That's a great use case for a breakpoint!
156156

157157
But if I add a breakpoint in `<MenuItemsList />`, it will trigger on _every menu item_ that gets rendered. This will force me to step through irrelevant items before I get to the one I want, wasting my time.
158158

159-
Instead, I will use a _conditional breakpoint_. It's like a regular breakpoint but it will only "activate" when a certain condition is met. What's great about this kind of breakpoints is that I can use expressions, accessing anything within the scope to write my condition.
159+
Instead, I will use a _conditional breakpoint_. It's like a regular breakpoint but it will only "activate" when a certain condition is met. What's great about these kind of breakpoints is that I can use expressions, accessing anything within the scope to write my condition.
160160

161161
![A screenshot of Visual Studio Code. The context menu of the gutter is open and the "Add Conditional Breakpoint" menu item is selected](/assets/04-03-conditional-breakpoint-01.png)
162162

@@ -193,4 +193,4 @@ const isActive = matchPath(
193193
)
194194
```
195195

196-
Now you know how to harvest the power of conditional breakpoints to debug your React components or any JavaScript code in general. Use it wisely!
196+
Now you know how to harness the power of conditional breakpoints to debug your React components or any JavaScript code in general. Use it wisely!

0 commit comments

Comments
 (0)