1010 * governing permissions and limitations under the License.
1111 */
1212
13- import { fireEvent , render } from '@testing-library/react' ;
13+ import { act , fireEvent , render } from '@testing-library/react' ;
1414import { FocusScope , useFocusManager } from '../' ;
1515import React from 'react' ;
1616import ReactDOM from 'react-dom' ;
@@ -38,7 +38,7 @@ describe('FocusScope', function () {
3838 let input2 = getByTestId ( 'input2' ) ;
3939 let input3 = getByTestId ( 'input3' ) ;
4040
41- input1 . focus ( ) ;
41+ act ( ( ) => { input1 . focus ( ) ; } ) ;
4242 expect ( document . activeElement ) . toBe ( input1 ) ;
4343
4444 fireEvent . keyDown ( document . activeElement , { key : 'Tab' } ) ;
@@ -77,7 +77,7 @@ describe('FocusScope', function () {
7777 let input2 = getByTestId ( 'input2' ) ;
7878 let input3 = getByTestId ( 'input3' ) ;
7979
80- input1 . focus ( ) ;
80+ act ( ( ) => { input1 . focus ( ) ; } ) ;
8181 expect ( document . activeElement ) . toBe ( input1 ) ;
8282
8383 fireEvent . keyDown ( document . activeElement , { key : 'Tab' } ) ;
@@ -114,7 +114,7 @@ describe('FocusScope', function () {
114114 let input2 = getByTestId ( 'input2' ) ;
115115 let input3 = getByTestId ( 'input3' ) ;
116116
117- input1 . focus ( ) ;
117+ act ( ( ) => { input1 . focus ( ) ; } ) ;
118118 expect ( document . activeElement ) . toBe ( input1 ) ;
119119
120120 fireEvent . keyDown ( document . activeElement , { key : 'Tab' } ) ;
@@ -147,7 +147,7 @@ describe('FocusScope', function () {
147147
148148 let input1 = getByTestId ( 'input1' ) ;
149149
150- input1 . focus ( ) ;
150+ act ( ( ) => { input1 . focus ( ) ; } ) ;
151151 expect ( document . activeElement ) . toBe ( input1 ) ;
152152
153153 fireEvent . keyDown ( document . activeElement , { key : 'Tab' , altKey : true } ) ;
@@ -177,7 +177,7 @@ describe('FocusScope', function () {
177177 let input5 = getByTestId ( 'input5' ) ;
178178 let input6 = getByTestId ( 'input6' ) ;
179179
180- input1 . focus ( ) ;
180+ act ( ( ) => { input1 . focus ( ) ; } ) ;
181181 expect ( document . activeElement ) . toBe ( input1 ) ;
182182
183183 fireEvent . keyDown ( document . activeElement , { key : 'Tab' } ) ;
@@ -198,7 +198,7 @@ describe('FocusScope', function () {
198198 fireEvent . keyDown ( document . activeElement , { key : 'Tab' , shiftKey : true } ) ;
199199 expect ( document . activeElement ) . toBe ( input1 ) ;
200200
201- input4 . focus ( ) ;
201+ act ( ( ) => { input4 . focus ( ) ; } ) ;
202202 expect ( document . activeElement ) . toBe ( input4 ) ;
203203
204204 fireEvent . keyDown ( document . activeElement , { key : 'Tab' } ) ;
@@ -236,18 +236,18 @@ describe('FocusScope', function () {
236236 let input2 = getByTestId ( 'input2' ) ;
237237 let outside = getByTestId ( 'outside' ) ;
238238
239- input1 . focus ( ) ;
239+ act ( ( ) => { input1 . focus ( ) ; } ) ;
240240 fireEvent . focusIn ( input1 ) ; // jsdom doesn't fire this automatically
241241 expect ( document . activeElement ) . toBe ( input1 ) ;
242242
243243 fireEvent . keyDown ( document . activeElement , { key : 'Tab' } ) ;
244244 fireEvent . focusIn ( input2 ) ;
245245 expect ( document . activeElement ) . toBe ( input2 ) ;
246246
247- input2 . blur ( ) ;
247+ act ( ( ) => { input2 . blur ( ) ; } ) ;
248248 expect ( document . activeElement ) . toBe ( input2 ) ;
249249
250- outside . focus ( ) ;
250+ act ( ( ) => { outside . focus ( ) ; } ) ;
251251 fireEvent . focusIn ( outside ) ;
252252 expect ( document . activeElement ) . toBe ( input2 ) ;
253253 } ) ;
@@ -265,15 +265,15 @@ describe('FocusScope', function () {
265265 let input1 = getByTestId ( 'input1' ) ;
266266 let input2 = getByTestId ( 'input2' ) ;
267267
268- input1 . focus ( ) ;
268+ act ( ( ) => { input1 . focus ( ) ; } ) ;
269269 fireEvent . focusIn ( input1 ) ; // jsdom doesn't fire this automatically
270270 expect ( document . activeElement ) . toBe ( input1 ) ;
271271
272272 fireEvent . keyDown ( document . activeElement , { key : 'Tab' } ) ;
273273 fireEvent . focusIn ( input2 ) ;
274274 expect ( document . activeElement ) . toBe ( input2 ) ;
275275
276- input2 . blur ( ) ;
276+ act ( ( ) => { input2 . blur ( ) ; } ) ;
277277 expect ( document . activeElement ) . toBe ( input2 ) ;
278278 fireEvent . focusOut ( input2 ) ;
279279 expect ( document . activeElement ) . toBe ( input2 ) ;
@@ -300,7 +300,7 @@ describe('FocusScope', function () {
300300 let { getByTestId, rerender} = render ( < Test /> ) ;
301301
302302 let outside = getByTestId ( 'outside' ) ;
303- outside . focus ( ) ;
303+ act ( ( ) => { outside . focus ( ) ; } ) ;
304304
305305 rerender ( < Test show /> ) ;
306306
@@ -333,15 +333,15 @@ describe('FocusScope', function () {
333333 let { getByTestId, rerender} = render ( < Test /> ) ;
334334
335335 let trigger = getByTestId ( 'trigger' ) ;
336- trigger . focus ( ) ;
336+ act ( ( ) => { trigger . focus ( ) ; } ) ;
337337
338338 rerender ( < Test show /> ) ;
339339
340340 let input1 = getByTestId ( 'input1' ) ;
341341 expect ( document . activeElement ) . toBe ( input1 ) ;
342342
343343 let input3 = getByTestId ( 'input3' ) ;
344- input3 . focus ( ) ;
344+ act ( ( ) => { input3 . focus ( ) ; } ) ;
345345
346346 fireEvent . keyDown ( input3 , { key : 'Tab' } ) ;
347347 expect ( document . activeElement ) . toBe ( getByTestId ( 'after' ) ) ;
@@ -368,7 +368,7 @@ describe('FocusScope', function () {
368368 let { getByTestId, rerender} = render ( < Test /> ) ;
369369
370370 let trigger = getByTestId ( 'trigger' ) ;
371- trigger . focus ( ) ;
371+ act ( ( ) => { trigger . focus ( ) ; } ) ;
372372
373373 rerender ( < Test show /> ) ;
374374
@@ -400,15 +400,15 @@ describe('FocusScope', function () {
400400 let { getByTestId, rerender} = render ( < Test /> ) ;
401401
402402 let trigger = getByTestId ( 'trigger' ) ;
403- trigger . focus ( ) ;
403+ act ( ( ) => { trigger . focus ( ) ; } ) ;
404404
405405 rerender ( < Test show /> ) ;
406406
407407 let input1 = getByTestId ( 'input1' ) ;
408408 expect ( document . activeElement ) . toBe ( input1 ) ;
409409
410410 let input3 = getByTestId ( 'input3' ) ;
411- input3 . focus ( ) ;
411+ act ( ( ) => { input3 . focus ( ) ; } ) ;
412412
413413 fireEvent . keyDown ( input3 , { key : 'Tab' } ) ;
414414 expect ( document . activeElement ) . toBe ( getByTestId ( 'after' ) ) ;
@@ -471,7 +471,7 @@ describe('FocusScope', function () {
471471 let item2 = getByTestId ( 'item2' ) ;
472472 let item3 = getByTestId ( 'item3' ) ;
473473
474- item1 . focus ( ) ;
474+ act ( ( ) => { item1 . focus ( ) ; } ) ;
475475
476476 fireEvent . click ( item1 ) ;
477477 expect ( document . activeElement ) . toBe ( item2 ) ;
@@ -508,7 +508,7 @@ describe('FocusScope', function () {
508508 let item2 = getByTestId ( 'item2' ) ;
509509 let item3 = getByTestId ( 'item3' ) ;
510510
511- item1 . focus ( ) ;
511+ act ( ( ) => { item1 . focus ( ) ; } ) ;
512512
513513 fireEvent . click ( item1 ) ;
514514 expect ( document . activeElement ) . toBe ( item2 ) ;
@@ -544,7 +544,7 @@ describe('FocusScope', function () {
544544 let item1 = getByTestId ( 'item1' ) ;
545545 let item3 = getByTestId ( 'item3' ) ;
546546
547- item1 . focus ( ) ;
547+ act ( ( ) => { item1 . focus ( ) ; } ) ;
548548
549549 fireEvent . click ( item1 ) ;
550550 expect ( document . activeElement ) . toBe ( item3 ) ;
@@ -575,7 +575,7 @@ describe('FocusScope', function () {
575575 let item2 = getByTestId ( 'item2' ) ;
576576 let item3 = getByTestId ( 'item3' ) ;
577577
578- item3 . focus ( ) ;
578+ act ( ( ) => { item3 . focus ( ) ; } ) ;
579579
580580 fireEvent . click ( item3 ) ;
581581 expect ( document . activeElement ) . toBe ( item2 ) ;
@@ -612,7 +612,7 @@ describe('FocusScope', function () {
612612 let item2 = getByTestId ( 'item2' ) ;
613613 let item3 = getByTestId ( 'item3' ) ;
614614
615- item3 . focus ( ) ;
615+ act ( ( ) => { item3 . focus ( ) ; } ) ;
616616
617617 fireEvent . click ( item3 ) ;
618618 expect ( document . activeElement ) . toBe ( item2 ) ;
@@ -648,7 +648,7 @@ describe('FocusScope', function () {
648648 let item1 = getByTestId ( 'item1' ) ;
649649 let item3 = getByTestId ( 'item3' ) ;
650650
651- item3 . focus ( ) ;
651+ act ( ( ) => { item3 . focus ( ) ; } ) ;
652652
653653 fireEvent . click ( item3 ) ;
654654 expect ( document . activeElement ) . toBe ( item1 ) ;
@@ -681,14 +681,14 @@ describe('FocusScope', function () {
681681 let { getByTestId, rerender} = render ( < Test /> ) ;
682682 // Set a focused node and make first FocusScope the active scope
683683 let input1 = getByTestId ( 'input1' ) ;
684- input1 . focus ( ) ;
684+ act ( ( ) => { input1 . focus ( ) ; } ) ;
685685 fireEvent . focusIn ( input1 ) ;
686686 expect ( document . activeElement ) . toBe ( input1 ) ;
687687
688688 rerender ( < Test show /> ) ;
689689 expect ( document . activeElement ) . toBe ( input1 ) ;
690690 let input3 = getByTestId ( 'input3' ) ;
691- input3 . focus ( ) ;
691+ act ( ( ) => { input3 . focus ( ) ; } ) ;
692692 fireEvent . focusIn ( input3 ) ;
693693 expect ( document . activeElement ) . toBe ( input3 ) ;
694694 } ) ;
0 commit comments