File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
packages/react-components/react-list/library/src Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,15 @@ import { ListProps } from './List.types';
66import { ListItem } from '../ListItem/ListItem' ;
77import { ListItemActionEventData } from '../ListItem/ListItem.types' ;
88import { EventHandler } from '@fluentui/react-utilities' ;
9+ import { resetIdsForTests } from '@fluentui/react-utilities' ;
10+
11+ // Mock useId from @fluentui /react-utilities to return CSS-safe IDs without special characters.
12+ // React's useId generates IDs with commas that create invalid CSS selectors in JSDOM 25+,
13+ // causing console.error logs that React 19's act() collects as AggregateError.
14+ jest . mock ( '@fluentui/react-utilities' , ( ) => ( {
15+ ...jest . requireActual ( '@fluentui/react-utilities' ) ,
16+ ...jest . requireActual ( '../../testing/createUseIdMock' ) . createUseIdMock ( ) ,
17+ } ) ) ;
918
1019function expectListboxItemSelected ( item : HTMLElement , selected : boolean ) {
1120 expect ( item . getAttribute ( 'aria-selected' ) ) . toBe ( selected . toString ( ) ) ;
@@ -58,8 +67,13 @@ describe('List', () => {
5867 // and false warnings about the mismatched roles because of tabster not working reliably in tests.
5968 const consoleWarn = jest . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => jest . fn ( ) ) ;
6069
70+ afterEach ( ( ) => {
71+ resetIdsForTests ( ) ;
72+ } ) ;
73+
6174 afterAll ( ( ) => {
6275 consoleWarn . mockRestore ( ) ;
76+ jest . clearAllMocks ( ) ;
6377 } ) ;
6478
6579 describe ( 'rendering' , ( ) => {
Original file line number Diff line number Diff line change 1+ 'use client' ;
2+
3+ import * as React from 'react' ;
4+
5+ export function createUseIdMock ( ) : { useId : ( prefix : string ) => string ; resetIdsForTests : ( ) => void } {
6+ let idCounter = 0 ;
7+
8+ return {
9+ useId : jest . fn ( ) . mockImplementation ( ( prefix : string ) => {
10+ return React . useMemo ( ( ) => {
11+ idCounter += 1 ;
12+ return `${ prefix } ${ idCounter } ` ;
13+ } , [ prefix ] ) ;
14+ } ) ,
15+ resetIdsForTests : ( ) => {
16+ idCounter = 0 ;
17+ } ,
18+ } ;
19+ }
You can’t perform that action at this time.
0 commit comments