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
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!
4
4
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:
6
6
7
7
1. Locate the line of code you want to set a breakpoint at;
8
8
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.
11
11
12
12
> 🦉 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.
13
13
14
-
👨💼 In this exercise, I will have a few tasks for you.
14
+
👨💼 In this exercise, I have a few tasks for you:
15
15
16
-
1. Replace the `debugger` statements in the <InlineFilefile="./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 <InlineFilefile="./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.
17
17
1. Complete the test case in <InlineFilefile="./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.
Copy file name to clipboardExpand all lines: exercises/04.debugging/03.solution.breakpoints/README.mdx
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,30 +133,30 @@ Received:
133
133
134
134
Looks like the current page link that gets rendered is the "Dashboard" link and not "Analytics". This demands some debugging.
135
135
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.
137
137
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:
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:
146
146
147
147

148
148
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.
150
150
151
151
> 🦉 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".
152
152
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.
154
154
155
155
That's a great use case for a breakpoint!
156
156
157
157
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.
158
158
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.
160
160
161
161

162
162
@@ -193,4 +193,4 @@ const isActive = matchPath(
193
193
)
194
194
```
195
195
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