import React from 'react'; import { render, fireEvent } from '@testing-library/react'; import { ResourceState } from './ResourceState'; const defaultProps: any = { state: 'error', message: 'This is a test error!', handleReload: jest.fn(), }; describe('ResourceError', () => { it('should render the component with the correct error message', () => { const { getByText } = render(); const errorMessage = getByText(defaultProps.message); expect(errorMessage).toBeInTheDocument(); }); it('should call the reload function when the button is pressed', () => { const { getByRole } = render(); const buttonElement = getByRole('button'); fireEvent.click(buttonElement); expect(defaultProps.handleReload).toHaveBeenCalledTimes(1); }); });