10
10
* governing permissions and limitations under the License.
11
11
*/
12
12
13
- import { fireEvent , render } from '@testing-library/react' ;
13
+ import { act , fireEvent , render } from '@testing-library/react' ;
14
14
import { FocusScope , useFocusManager } from '../' ;
15
15
import React from 'react' ;
16
16
import ReactDOM from 'react-dom' ;
@@ -38,7 +38,7 @@ describe('FocusScope', function () {
38
38
let input2 = getByTestId ( 'input2' ) ;
39
39
let input3 = getByTestId ( 'input3' ) ;
40
40
41
- input1 . focus ( ) ;
41
+ act ( ( ) => { input1 . focus ( ) ; } ) ;
42
42
expect ( document . activeElement ) . toBe ( input1 ) ;
43
43
44
44
fireEvent . keyDown ( document . activeElement , { key : 'Tab' } ) ;
@@ -77,7 +77,7 @@ describe('FocusScope', function () {
77
77
let input2 = getByTestId ( 'input2' ) ;
78
78
let input3 = getByTestId ( 'input3' ) ;
79
79
80
- input1 . focus ( ) ;
80
+ act ( ( ) => { input1 . focus ( ) ; } ) ;
81
81
expect ( document . activeElement ) . toBe ( input1 ) ;
82
82
83
83
fireEvent . keyDown ( document . activeElement , { key : 'Tab' } ) ;
@@ -114,7 +114,7 @@ describe('FocusScope', function () {
114
114
let input2 = getByTestId ( 'input2' ) ;
115
115
let input3 = getByTestId ( 'input3' ) ;
116
116
117
- input1 . focus ( ) ;
117
+ act ( ( ) => { input1 . focus ( ) ; } ) ;
118
118
expect ( document . activeElement ) . toBe ( input1 ) ;
119
119
120
120
fireEvent . keyDown ( document . activeElement , { key : 'Tab' } ) ;
@@ -147,7 +147,7 @@ describe('FocusScope', function () {
147
147
148
148
let input1 = getByTestId ( 'input1' ) ;
149
149
150
- input1 . focus ( ) ;
150
+ act ( ( ) => { input1 . focus ( ) ; } ) ;
151
151
expect ( document . activeElement ) . toBe ( input1 ) ;
152
152
153
153
fireEvent . keyDown ( document . activeElement , { key : 'Tab' , altKey : true } ) ;
@@ -177,7 +177,7 @@ describe('FocusScope', function () {
177
177
let input5 = getByTestId ( 'input5' ) ;
178
178
let input6 = getByTestId ( 'input6' ) ;
179
179
180
- input1 . focus ( ) ;
180
+ act ( ( ) => { input1 . focus ( ) ; } ) ;
181
181
expect ( document . activeElement ) . toBe ( input1 ) ;
182
182
183
183
fireEvent . keyDown ( document . activeElement , { key : 'Tab' } ) ;
@@ -198,7 +198,7 @@ describe('FocusScope', function () {
198
198
fireEvent . keyDown ( document . activeElement , { key : 'Tab' , shiftKey : true } ) ;
199
199
expect ( document . activeElement ) . toBe ( input1 ) ;
200
200
201
- input4 . focus ( ) ;
201
+ act ( ( ) => { input4 . focus ( ) ; } ) ;
202
202
expect ( document . activeElement ) . toBe ( input4 ) ;
203
203
204
204
fireEvent . keyDown ( document . activeElement , { key : 'Tab' } ) ;
@@ -236,18 +236,18 @@ describe('FocusScope', function () {
236
236
let input2 = getByTestId ( 'input2' ) ;
237
237
let outside = getByTestId ( 'outside' ) ;
238
238
239
- input1 . focus ( ) ;
239
+ act ( ( ) => { input1 . focus ( ) ; } ) ;
240
240
fireEvent . focusIn ( input1 ) ; // jsdom doesn't fire this automatically
241
241
expect ( document . activeElement ) . toBe ( input1 ) ;
242
242
243
243
fireEvent . keyDown ( document . activeElement , { key : 'Tab' } ) ;
244
244
fireEvent . focusIn ( input2 ) ;
245
245
expect ( document . activeElement ) . toBe ( input2 ) ;
246
246
247
- input2 . blur ( ) ;
247
+ act ( ( ) => { input2 . blur ( ) ; } ) ;
248
248
expect ( document . activeElement ) . toBe ( input2 ) ;
249
249
250
- outside . focus ( ) ;
250
+ act ( ( ) => { outside . focus ( ) ; } ) ;
251
251
fireEvent . focusIn ( outside ) ;
252
252
expect ( document . activeElement ) . toBe ( input2 ) ;
253
253
} ) ;
@@ -265,15 +265,15 @@ describe('FocusScope', function () {
265
265
let input1 = getByTestId ( 'input1' ) ;
266
266
let input2 = getByTestId ( 'input2' ) ;
267
267
268
- input1 . focus ( ) ;
268
+ act ( ( ) => { input1 . focus ( ) ; } ) ;
269
269
fireEvent . focusIn ( input1 ) ; // jsdom doesn't fire this automatically
270
270
expect ( document . activeElement ) . toBe ( input1 ) ;
271
271
272
272
fireEvent . keyDown ( document . activeElement , { key : 'Tab' } ) ;
273
273
fireEvent . focusIn ( input2 ) ;
274
274
expect ( document . activeElement ) . toBe ( input2 ) ;
275
275
276
- input2 . blur ( ) ;
276
+ act ( ( ) => { input2 . blur ( ) ; } ) ;
277
277
expect ( document . activeElement ) . toBe ( input2 ) ;
278
278
fireEvent . focusOut ( input2 ) ;
279
279
expect ( document . activeElement ) . toBe ( input2 ) ;
@@ -300,7 +300,7 @@ describe('FocusScope', function () {
300
300
let { getByTestId, rerender} = render ( < Test /> ) ;
301
301
302
302
let outside = getByTestId ( 'outside' ) ;
303
- outside . focus ( ) ;
303
+ act ( ( ) => { outside . focus ( ) ; } ) ;
304
304
305
305
rerender ( < Test show /> ) ;
306
306
@@ -333,15 +333,15 @@ describe('FocusScope', function () {
333
333
let { getByTestId, rerender} = render ( < Test /> ) ;
334
334
335
335
let trigger = getByTestId ( 'trigger' ) ;
336
- trigger . focus ( ) ;
336
+ act ( ( ) => { trigger . focus ( ) ; } ) ;
337
337
338
338
rerender ( < Test show /> ) ;
339
339
340
340
let input1 = getByTestId ( 'input1' ) ;
341
341
expect ( document . activeElement ) . toBe ( input1 ) ;
342
342
343
343
let input3 = getByTestId ( 'input3' ) ;
344
- input3 . focus ( ) ;
344
+ act ( ( ) => { input3 . focus ( ) ; } ) ;
345
345
346
346
fireEvent . keyDown ( input3 , { key : 'Tab' } ) ;
347
347
expect ( document . activeElement ) . toBe ( getByTestId ( 'after' ) ) ;
@@ -368,7 +368,7 @@ describe('FocusScope', function () {
368
368
let { getByTestId, rerender} = render ( < Test /> ) ;
369
369
370
370
let trigger = getByTestId ( 'trigger' ) ;
371
- trigger . focus ( ) ;
371
+ act ( ( ) => { trigger . focus ( ) ; } ) ;
372
372
373
373
rerender ( < Test show /> ) ;
374
374
@@ -400,15 +400,15 @@ describe('FocusScope', function () {
400
400
let { getByTestId, rerender} = render ( < Test /> ) ;
401
401
402
402
let trigger = getByTestId ( 'trigger' ) ;
403
- trigger . focus ( ) ;
403
+ act ( ( ) => { trigger . focus ( ) ; } ) ;
404
404
405
405
rerender ( < Test show /> ) ;
406
406
407
407
let input1 = getByTestId ( 'input1' ) ;
408
408
expect ( document . activeElement ) . toBe ( input1 ) ;
409
409
410
410
let input3 = getByTestId ( 'input3' ) ;
411
- input3 . focus ( ) ;
411
+ act ( ( ) => { input3 . focus ( ) ; } ) ;
412
412
413
413
fireEvent . keyDown ( input3 , { key : 'Tab' } ) ;
414
414
expect ( document . activeElement ) . toBe ( getByTestId ( 'after' ) ) ;
@@ -471,7 +471,7 @@ describe('FocusScope', function () {
471
471
let item2 = getByTestId ( 'item2' ) ;
472
472
let item3 = getByTestId ( 'item3' ) ;
473
473
474
- item1 . focus ( ) ;
474
+ act ( ( ) => { item1 . focus ( ) ; } ) ;
475
475
476
476
fireEvent . click ( item1 ) ;
477
477
expect ( document . activeElement ) . toBe ( item2 ) ;
@@ -508,7 +508,7 @@ describe('FocusScope', function () {
508
508
let item2 = getByTestId ( 'item2' ) ;
509
509
let item3 = getByTestId ( 'item3' ) ;
510
510
511
- item1 . focus ( ) ;
511
+ act ( ( ) => { item1 . focus ( ) ; } ) ;
512
512
513
513
fireEvent . click ( item1 ) ;
514
514
expect ( document . activeElement ) . toBe ( item2 ) ;
@@ -544,7 +544,7 @@ describe('FocusScope', function () {
544
544
let item1 = getByTestId ( 'item1' ) ;
545
545
let item3 = getByTestId ( 'item3' ) ;
546
546
547
- item1 . focus ( ) ;
547
+ act ( ( ) => { item1 . focus ( ) ; } ) ;
548
548
549
549
fireEvent . click ( item1 ) ;
550
550
expect ( document . activeElement ) . toBe ( item3 ) ;
@@ -575,7 +575,7 @@ describe('FocusScope', function () {
575
575
let item2 = getByTestId ( 'item2' ) ;
576
576
let item3 = getByTestId ( 'item3' ) ;
577
577
578
- item3 . focus ( ) ;
578
+ act ( ( ) => { item3 . focus ( ) ; } ) ;
579
579
580
580
fireEvent . click ( item3 ) ;
581
581
expect ( document . activeElement ) . toBe ( item2 ) ;
@@ -612,7 +612,7 @@ describe('FocusScope', function () {
612
612
let item2 = getByTestId ( 'item2' ) ;
613
613
let item3 = getByTestId ( 'item3' ) ;
614
614
615
- item3 . focus ( ) ;
615
+ act ( ( ) => { item3 . focus ( ) ; } ) ;
616
616
617
617
fireEvent . click ( item3 ) ;
618
618
expect ( document . activeElement ) . toBe ( item2 ) ;
@@ -648,7 +648,7 @@ describe('FocusScope', function () {
648
648
let item1 = getByTestId ( 'item1' ) ;
649
649
let item3 = getByTestId ( 'item3' ) ;
650
650
651
- item3 . focus ( ) ;
651
+ act ( ( ) => { item3 . focus ( ) ; } ) ;
652
652
653
653
fireEvent . click ( item3 ) ;
654
654
expect ( document . activeElement ) . toBe ( item1 ) ;
@@ -681,14 +681,14 @@ describe('FocusScope', function () {
681
681
let { getByTestId, rerender} = render ( < Test /> ) ;
682
682
// Set a focused node and make first FocusScope the active scope
683
683
let input1 = getByTestId ( 'input1' ) ;
684
- input1 . focus ( ) ;
684
+ act ( ( ) => { input1 . focus ( ) ; } ) ;
685
685
fireEvent . focusIn ( input1 ) ;
686
686
expect ( document . activeElement ) . toBe ( input1 ) ;
687
687
688
688
rerender ( < Test show /> ) ;
689
689
expect ( document . activeElement ) . toBe ( input1 ) ;
690
690
let input3 = getByTestId ( 'input3' ) ;
691
- input3 . focus ( ) ;
691
+ act ( ( ) => { input3 . focus ( ) ; } ) ;
692
692
fireEvent . focusIn ( input3 ) ;
693
693
expect ( document . activeElement ) . toBe ( input3 ) ;
694
694
} ) ;
0 commit comments