Skip to content

Commit b02f3bb

Browse files
committed
test(react-popover): mock useFocusFinders for dev-warning tests in jsdom
1 parent 0254b82 commit b02f3bb

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

  • packages/react-components/react-popover/library/src/components/Popover

packages/react-components/react-popover/library/src/components/Popover/Popover.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ import { usePopover_unstable } from './usePopover';
55
import { isConformant } from '../../testing/isConformant';
66
import type { PopoverProps } from './Popover.types';
77

8+
// useFocusFinders requires tabster to be initialized on the document (via FluentProvider),
9+
// which does not happen in unit tests. Mock it with a real DOM-based implementation
10+
// so findFirstFocusable works correctly in jsdom.
11+
jest.mock('@fluentui/react-tabster', () => {
12+
const FOCUSABLE_SELECTOR =
13+
'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
14+
return {
15+
...jest.requireActual('@fluentui/react-tabster'),
16+
useFocusFinders: () => ({
17+
findFirstFocusable: (container: HTMLElement | null) =>
18+
container?.querySelector<HTMLElement>(FOCUSABLE_SELECTOR) ?? undefined,
19+
}),
20+
};
21+
});
22+
823
describe('Popover', () => {
924
isConformant({
1025
Component: Popover,

0 commit comments

Comments
 (0)