import React from 'react'; import { render, screen } from '@testing-library/react'; import { CardTitle } from '../CardTitle'; import { CardContext } from '../Card'; describe('CardTitle', () => { test('renders with PatternFly Core styles', () => { const { asFragment } = render(text); expect(asFragment()).toMatchSnapshot(); }); test('className is added to the root element', () => { render(text); expect(screen.getByText('text')).toHaveClass('extra-class'); }); test('extra props are spread to the root element', () => { const testId = 'card-header'; render(); expect(screen.getByTestId(testId)).toBeInTheDocument(); }); test('calls the registerTitleId function provided by the CardContext with the generated title id', () => { const mockRegisterTitleId = jest.fn(); render( text ); expect(mockRegisterTitleId).toHaveBeenCalledWith('card-title'); }); });