Skip to content

Commit dc04152

Browse files
committed
address code rabbit feedback
1 parent c3d3c38 commit dc04152

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tests/Menu.spec.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ describe('Menu', () => {
794794

795795
it('should correctly handle invalid mergedActiveKey and fallback to focusable elements', async () => {
796796
// Mock to force make menu item visible
797-
spyElementPrototypes(HTMLElement, {
797+
const domSpy = spyElementPrototypes(HTMLElement, {
798798
offsetParent: {
799799
get() {
800800
return this.parentElement;
@@ -803,7 +803,6 @@ describe('Menu', () => {
803803
});
804804

805805
const menuRef = React.createRef<MenuRef>();
806-
const focusSpy = jest.fn();
807806

808807
const TestApp = () => {
809808
const [items, setItems] = React.useState([
@@ -832,7 +831,7 @@ describe('Menu', () => {
832831
);
833832
};
834833

835-
const { getByTestId } = await act(async () => render(<TestApp />));
834+
const { getByTestId } = render(<TestApp />);
836835

837836
const removeButton = getByTestId('remove-button');
838837

@@ -849,15 +848,16 @@ describe('Menu', () => {
849848

850849
// mock focus on item 1 to make sure it gets focused
851850
const item1 = getByTestId('item1');
852-
item1.focus = focusSpy;
851+
const focusSpy = jest.spyOn(item1, 'focus').mockImplementation(() => {});
853852

854853
// when we call focus(), it should properly handle the case where
855854
// mergedActiveKey ("item2") no longer exists
856-
await act(async () => {
857-
menuRef.current.focus();
858-
});
855+
menuRef.current.focus();
859856

860857
expect(focusSpy).toHaveBeenCalled();
858+
// cleanup
859+
focusSpy.mockRestore();
860+
domSpy?.mockRestore?.();
861861
});
862862
});
863863
/* eslint-enable */

0 commit comments

Comments
 (0)