diff --git a/src/components/SelectionList/BaseListItem.tsx b/src/components/SelectionList/BaseListItem.tsx index 57fd457b4b00..0bcf8cd978c5 100644 --- a/src/components/SelectionList/BaseListItem.tsx +++ b/src/components/SelectionList/BaseListItem.tsx @@ -48,6 +48,7 @@ function BaseListItem({ // Sync focus on an item useSyncFocus(pressableRef, !!isFocused, shouldSyncFocus); const handleMouseLeave = (e: React.MouseEvent) => { + bind.onMouseLeave(); e.stopPropagation(); setMouseUp(); }; diff --git a/tests/ui/BaseListItemTest.tsx b/tests/ui/BaseListItemTest.tsx new file mode 100644 index 000000000000..39bb1a245f7f --- /dev/null +++ b/tests/ui/BaseListItemTest.tsx @@ -0,0 +1,35 @@ +import {fireEvent, render, screen} from '@testing-library/react-native'; +import BaseListItem from '@components/SelectionList/BaseListItem'; +import useHover from '@hooks/useHover'; +import CONST from '@src/CONST'; + +jest.mock('@hooks/useHover', () => jest.fn()); + +const mockedUseHover = useHover as jest.MockedFunction; + +describe('BaseListItem', () => { + it('hover should work correctly', () => { + const mouseEnterMock = jest.fn(); + const mouseLeaveMock = jest.fn(); + mockedUseHover.mockReturnValue({ + hovered: false, + bind: { + onMouseEnter: mouseEnterMock, + onMouseLeave: mouseLeaveMock, + }, + }); + render( + {}} + showTooltip={false} + isFocused={false} + />, + ); + const testID = `${CONST.BASE_LIST_ITEM_TEST_ID}1`; + fireEvent(screen.getByTestId(testID), 'mouseEnter'); + expect(mouseEnterMock).toBeCalled(); + fireEvent(screen.getByTestId(testID), 'mouseLeave', {stopPropagation: jest.fn()}); + expect(mouseLeaveMock).toBeCalled(); + }); +});