From 11f86ffbe75132cefb935c385eadea4256bffb0a Mon Sep 17 00:00:00 2001 From: Poojesh Shetty Date: Sun, 17 Jul 2022 15:47:42 +0530 Subject: [PATCH] feat: update homecontainer test --- .../HomeContainer/tests/index.test.tsx | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/app/containers/HomeContainer/tests/index.test.tsx b/app/containers/HomeContainer/tests/index.test.tsx index edfba83..a2367d5 100644 --- a/app/containers/HomeContainer/tests/index.test.tsx +++ b/app/containers/HomeContainer/tests/index.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { timeout, renderProvider } from '@utils/testUtils'; import { HomeContainerTest as HomeContainer, mapDispatchToProps } from '../index'; import { HomeContainerProps, LaunchData } from '../types'; -import { fireEvent } from '@testing-library/react'; +import { fireEvent, waitFor } from '@testing-library/react'; import { createIntl } from 'react-intl'; import { translationMessages } from '@app/i18n'; import history from '@app/utils/history'; @@ -205,12 +205,12 @@ describe(' tests', () => { fireEvent.change(getByTestId('search-bar'), { target: { value: 'a' } }); - await timeout(500); + await waitFor(() => timeout(500)); expect(history.location.search).toContain('mission_name=a'); fireEvent.change(getByTestId('search-bar'), { target: { value: '' } }); - await timeout(500); + await waitFor(() => timeout(500)); expect(history.location.search).not.toContain('mission='); }); it('should dispatchLaunchList on update on mount if there is no launchQuery and no data already persisted', async () => { @@ -221,31 +221,21 @@ describe(' tests', () => { it('should sort the launches by date in ASC', async () => { history.location.search = '?order=unknown'; - const { getByText, getByRole, rerender } = renderProvider( + const { getByText, getByRole } = renderProvider( ); fireEvent.mouseDown(getByRole('combobox')!); fireEvent.click(getByText('ASC')); - expect(history.location.search).toContain('order=asc'); - renderProvider( - , - undefined, - rerender as any - ); + await waitFor(() => expect(history.location.search).toContain('order=asc')); }); it('should sort the launches by date in DESC', async () => { - const { getByText, getByRole, rerender } = renderProvider( + const { getByText, getByRole } = renderProvider( ); fireEvent.mouseDown(getByRole('combobox')!); fireEvent.click(getByText('DESC')); - expect(history.location.search).toContain('order=desc'); - renderProvider( - , - undefined, - rerender as any - ); + await waitFor(() => expect(history.location.search).toContain('order=desc')); }); it('should push to first page if no data found in the current page', async () => { @@ -273,13 +263,15 @@ describe(' tests', () => { expect(history.location.search).toContain('page=1'); }); - it('should clear sort when clicked on clear sort button', () => { + it('should clear sort when clicked on clear sort button', async () => { const { getByText, getByRole, getByTestId, rerender } = renderProvider( ); fireEvent.mouseDown(getByRole('combobox')!); fireEvent.click(getByText('DESC')); - renderProvider(, {}, rerender as any); + await waitFor(() => { + renderProvider(, {}, rerender as any); + }); fireEvent.click(getByTestId('clear-sort')); expect(history.location.search).not.toContain('order=desc'); });