Skip to content

Commit 4c2e387

Browse files
committed
polished test
1 parent a9fdb7f commit 4c2e387

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/use-dropdown-menu.test.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const TestComponent: React.FC<Props> = ({ options }) => {
2828
key={i}
2929
id={`menu-item-${i + 1}`}
3030
onClick={clickHandlers[i]}
31-
onMouseEnter={(): void => moveFocus(i)}
3231
href={i > 1 ? 'https://example.com' : undefined}
3332
>
3433
{i + 1} Item
@@ -46,6 +45,10 @@ const TestComponent: React.FC<Props> = ({ options }) => {
4645
Add Item
4746
</button>
4847

48+
<button data-testid='focus-third-item' onClick={(): void => moveFocus(2)}>
49+
Focus third item
50+
</button>
51+
4952
<span data-testid='is-open-indicator'>{isOpen ? 'true' : 'false'}</span>
5053
</React.Fragment>
5154
);
@@ -542,7 +545,7 @@ it('Moves the focus to the menu item with a label that starts with the correspon
542545
expect(screen.getByText('3 Item')).toHaveFocus();
543546
});
544547

545-
it('Moves the focus to the menu item currently hovered over by mouse', () => {
548+
it('Moves the focus to the provided menu item when `moveFocus` is called', () => {
546549
render(<TestComponent />);
547550

548551
userEvent.tab();
@@ -551,13 +554,7 @@ it('Moves the focus to the menu item currently hovered over by mouse', () => {
551554
skipClick: true,
552555
});
553556

554-
fireEvent(
555-
screen.getByText('3 Item'),
556-
new MouseEvent('mouseover', {
557-
bubbles: true,
558-
cancelable: true,
559-
})
560-
);
557+
userEvent.click(screen.getByTestId('focus-third-item'));
561558

562559
expect(screen.getByText('3 Item')).toHaveFocus();
563560
});

0 commit comments

Comments
 (0)