Skip to content

Commit 8a62f77

Browse files
committed
added unit test for space closing menu
1 parent de41615 commit 8a62f77

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/use-dropdown-menu.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,22 @@ it('Activates the click handler of a menu item after pressing enter while focuse
465465
expect(console.log).toHaveBeenCalledWith('Item one clicked');
466466
});
467467

468+
it('Closes the menu after pressing space on a menu item with a click handler', () => {
469+
render(<TestComponent />);
470+
471+
userEvent.tab();
472+
473+
userEvent.type(screen.getByText('Primary'), '{enter}', {
474+
skipClick: true,
475+
});
476+
477+
userEvent.type(screen.getByText('Item 1'), '{space}', {
478+
skipClick: true,
479+
});
480+
481+
expect(screen.getByTestId('is-open-indicator')).toHaveTextContent('false');
482+
});
483+
468484
it('Activates the click handler of a menu item after pressing space while focused on it', () => {
469485
render(<TestComponent />);
470486

0 commit comments

Comments
 (0)