import '@testing-library/jest-dom'; import * as optaFn from '../replaceTeamDetails'; describe('isNationalCompetition', () => { jest.spyOn(optaFn, 'isNationalCompetition'); it('should return TRUE if is in array of national competitions', async () => { const isNationalCompetition = optaFn.isNationalCompetition('3', 'football'); expect(optaFn.isNationalCompetition).toHaveBeenCalledWith('3', 'football'); expect(isNationalCompetition).toBe(true); }); it('should return FALSE if is in array of national competitions', async () => { const isNationalCompetition = optaFn.isNationalCompetition('8', 'football'); expect(optaFn.isNationalCompetition).toHaveBeenCalledWith('8', 'football'); expect(isNationalCompetition).toBe(false); }); }); describe('replaceTeamDetails', () => { jest.useFakeTimers(); it('should return correct team details', () => { jest.spyOn(optaFn, 'replaceTeamDetails'); const wrapper = document.createElement('div'); for (let i = 0; i < 5; i++) { const d = document.createElement('div'); d.className = 'team'; d.dataset.teamId = `${i}`; switch (i) { case 1: d.innerText = 'British & Irish Lions'; break; case 2: d.innerText = 'Quarter-Finalist'; break; case 3: d.innerText = 'Semi-Finalist'; break; case 4: d.innerText = 'Third Place'; break; default: d.innerText = `Team ${i}`; } wrapper.appendChild(d); } const mockCollection: HTMLCollection = wrapper.children; expect(mockCollection).toBeInstanceOf(HTMLCollection); expect(mockCollection.length).toBe(5); // call the function under test (adjust args if your signature differs) optaFn.replaceTeamDetails(mockCollection); expect(optaFn.replaceTeamDetails).toHaveBeenCalledWith(mockCollection); jest.advanceTimersByTime(500 * 3); // fast-forward time to ensure all intervals run const optaFnDiv = Array.from(mockCollection as HTMLCollectionOf< HTMLElement >); expect(optaFnDiv[0].innerText).toEqual('Team 0'); expect(optaFnDiv[1].innerText).toEqual('The Lions'); expect(optaFnDiv[2].innerText).toEqual('QF'); expect(optaFnDiv[3].innerText).toEqual('SF'); expect(optaFnDiv[4].innerText).toEqual('TBD'); }); });