UI/Card: Fix handling of 'onClick' callback (#31225)

This commit is contained in:
kay delaney 2021-02-16 13:11:37 +00:00 committed by GitHub
parent 350dcb999a
commit 38daf0cba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -0,0 +1,12 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import { Card } from './Card';
describe('Card', () => {
it('should execute callback when clicked', () => {
const callback = jest.fn();
render(<Card heading="Test Heading" onClick={callback} />);
fireEvent.click(screen.getByText('Test Heading'));
expect(callback).toBeCalledTimes(1);
});
});

View File

@ -101,7 +101,7 @@ export const Card: CardInterface = ({
const disableEvents = disabled && !actions;
const containerStyles = getContainerStyles(theme, disableEvents, disableHover);
const onCardClick = useCallback(() => (disableHover ? () => {} : onClick), [disableHover, onClick]);
const onCardClick = useCallback(() => (disableHover ? () => {} : onClick?.()), [disableHover, onClick]);
return (
<CardContainer