Skip to content

Commit

Permalink
test: fix options menu item tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasialanz committed Oct 3, 2024
1 parent fd74de7 commit 952d674
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/react/src/components/OptionsMenu/OptionsMenuItem.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import OptionsMenu, { OptionsMenuItem } from './';
import axe from '../../axe';

Expand All @@ -15,7 +16,8 @@ const defaultMenuProps = {
)
};

test('should call onSelect when menuitem is clicked', () => {
test('should call onSelect when menuitem is clicked', async () => {
const user = userEvent.setup();
const onSelect = jest.fn();

render(
Expand All @@ -24,23 +26,25 @@ test('should call onSelect when menuitem is clicked', () => {
</OptionsMenu>
);

fireEvent.click(screen.getByRole('menuitem'));
await user.click(screen.getByRole('menuitem'));

expect(onSelect).toBeCalled();
});

test('should not call onSelect when menuitem is disabled', () => {
test('should not call onSelect when menuitem is disabled', async () => {
const user = userEvent.setup();
const menuOnSelect = jest.fn();
const onSelect = jest.fn();

render(
<OptionsMenu {...defaultMenuProps} onSelect={onSelect}>
<OptionsMenu {...defaultMenuProps} onSelect={menuOnSelect}>
<OptionsMenuItem onSelect={onSelect} disabled>
option 1
</OptionsMenuItem>
</OptionsMenu>
);

fireEvent.click(screen.getByRole('menuitem'));
await user.click(screen.getByRole('menuitem'));

expect(onSelect).not.toBeCalled();
});
Expand Down

0 comments on commit 952d674

Please sign in to comment.