From 705dcbc98755fe231f9b9cf636701c2c1b132625 Mon Sep 17 00:00:00 2001 From: Akshat Gupta <88035400+Akshat76845@users.noreply.github.com> Date: Mon, 23 Dec 2024 04:16:07 +0530 Subject: [PATCH] Refactor : src/screens/OrgContribution component from Jest to Vitest (#2729) * Converted from Jest to Vitest * Converted the code from Jest to Vitest * Converted from Jest to Vitest --------- Co-authored-by: Akshat --- ...tion.test.tsx => OrgContribution.spec.tsx} | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) rename src/screens/OrgContribution/{OrgContribution.test.tsx => OrgContribution.spec.tsx} (80%) diff --git a/src/screens/OrgContribution/OrgContribution.test.tsx b/src/screens/OrgContribution/OrgContribution.spec.tsx similarity index 80% rename from src/screens/OrgContribution/OrgContribution.test.tsx rename to src/screens/OrgContribution/OrgContribution.spec.tsx index f9f63c6807..f12057a626 100644 --- a/src/screens/OrgContribution/OrgContribution.test.tsx +++ b/src/screens/OrgContribution/OrgContribution.spec.tsx @@ -1,9 +1,9 @@ -import React, { act } from 'react'; +import React from 'react'; import { MockedProvider } from '@apollo/react-testing'; import { render } from '@testing-library/react'; import { Provider } from 'react-redux'; import { BrowserRouter } from 'react-router-dom'; -import 'jest-location-mock'; +import { vi, describe, test, expect } from 'vitest'; import { I18nextProvider } from 'react-i18next'; import OrgContribution from './OrgContribution'; @@ -12,15 +12,20 @@ import i18nForTest from 'utils/i18nForTest'; import { StaticMockLink } from 'utils/StaticMockLink'; const link = new StaticMockLink([], true); async function wait(ms = 100): Promise { - await act(() => { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); + await new Promise((resolve) => { + setTimeout(resolve, ms); }); } describe('Organisation Contribution Page', () => { test('should render props and text elements test for the screen', async () => { + Object.defineProperty(window, 'location', { + value: { + assign: vi.fn(), + }, + writable: true, + }); + window.location.assign('/orglist'); const { container } = render( @@ -37,11 +42,10 @@ describe('Organisation Contribution Page', () => { expect(container.textContent).not.toBe('Loading data...'); await wait(); - expect(container.textContent).toMatch('Filter by Name'); expect(container.textContent).toMatch('Filter by Trans. ID'); expect(container.textContent).toMatch('Recent Stats'); expect(container.textContent).toMatch('Contribution'); - expect(window.location).toBeAt('/orglist'); + expect(window.location.assign).toHaveBeenCalledWith('/orglist'); }); });