File tree Expand file tree Collapse file tree
src/content/reference/react Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -117,26 +117,27 @@ Using `act` ensures that all updates have been applied before we make assertions
117117
118118To test events, wrap the event dispatch inside ` act() ` :
119119
120- ``` js {14,16 }
120+ ``` js {16,17 }
121121import {act } from ' react' ;
122122import ReactDOMClient from ' react-dom/client' ;
123123import Counter from ' ./Counter' ;
124124
125- it . only (' can render and update a counter' , async () => {
125+ it (' can render and update a counter' , async () => {
126126 const container = document .createElement (' div' );
127127 document .body .appendChild (container);
128128
129- await act ( async () => {
129+ await act (async () => {
130130 ReactDOMClient .createRoot (container).render (< Counter / > );
131131 });
132132
133+ const button = container .querySelector (' button' );
134+ const label = container .querySelector (' p' );
135+
133136 // ✅ Dispatch the event inside act().
134137 await act (async () => {
135138 button .dispatchEvent (new MouseEvent (' click' , { bubbles: true }));
136139 });
137140
138- const button = container .querySelector (' button' );
139- const label = container .querySelector (' p' );
140141 expect (label .textContent ).toBe (' You clicked 1 times' );
141142 expect (document .title ).toBe (' You clicked 1 times' );
142143});
You can’t perform that action at this time.
0 commit comments