import React from 'react'; import { render, act } from '@testing-library/react'; import 'regenerator-runtime'; import '@testing-library/jest-dom'; jest.mock('@times-components/image', () => ({ Placeholder: () => <>Placeholder })); const mockInitSettings = jest.fn(); const mockInitStyleSheet = jest.fn(); const mockInitComponent = jest.fn(); const mockInitElement = () => { const element = document.createElement('div'); element.appendChild(document.createTextNode('Widget')); return element; }; jest.mock('../../../../utils/config', () => ({ initSettings: mockInitSettings, initStyleSheet: mockInitStyleSheet, initScript: () => new Promise(resolve => resolve({})), initElement: mockInitElement, initComponent: mockInitComponent })); import { OptaMatchStatsTable } from '../OptaMatchStatsTable'; const requiredProps = { season: '2023', competition: 'premier-league', match: '123456', competitionName: 'Premier League' }; describe('OptaMatchStatsTable', () => { beforeEach(() => { jest.clearAllMocks(); }); it('should render correctly', async () => { const { asFragment } = render(); act(() => { mockInitComponent(); }); expect(mockInitSettings).toHaveBeenCalledTimes(1); expect(mockInitStyleSheet).toHaveBeenCalledTimes(1); expect(mockInitComponent).toHaveBeenCalledTimes(1); expect(asFragment()).toMatchSnapshot(); }); it('should render with isApp prop set to true', async () => { const { asFragment } = render( ); act(() => { mockInitComponent(); }); expect(asFragment()).toMatchSnapshot(); }); it('should render with isApp prop set to false', async () => { const { asFragment } = render( ); act(() => { mockInitComponent(); }); expect(asFragment()).toMatchSnapshot(); }); it('should initialize football stylesheet', () => { render(); expect(mockInitStyleSheet).toHaveBeenCalledWith('football'); }); it('should render with different season values', async () => { const { asFragment } = render( ); act(() => { mockInitComponent(); }); expect(asFragment()).toMatchSnapshot(); }); it('should render with different competition values', async () => { const { asFragment } = render( ); act(() => { mockInitComponent(); }); expect(asFragment()).toMatchSnapshot(); }); it('should render with different match values', async () => { const { asFragment } = render( ); act(() => { mockInitComponent(); }); expect(asFragment()).toMatchSnapshot(); }); });