From 5dbada86cdd7e8ec46a6d9bc5f19d132df53af27 Mon Sep 17 00:00:00 2001 From: Alessandro Menduni Date: Tue, 18 Apr 2023 12:13:02 +0200 Subject: [PATCH] Fix failing test due to change in renderHook result interface --- .../__tests__/useLoadingState.test.tsx | 32 +++++-------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/frontend/src/components/__tests__/useLoadingState.test.tsx b/frontend/src/components/__tests__/useLoadingState.test.tsx index 8962d6a0..01183b78 100644 --- a/frontend/src/components/__tests__/useLoadingState.test.tsx +++ b/frontend/src/components/__tests__/useLoadingState.test.tsx @@ -1,4 +1,4 @@ -import {renderHook} from '@testing-library/react' +import {renderHook, waitFor} from '@testing-library/react' import {useLoadingState} from '../useLoadingState' import {Box} from '@cloudscape-design/components' import React from 'react' @@ -44,9 +44,9 @@ jest.mock('../../model', () => { }) function expectDataToBeRequested() { - expect(mockGetAppConfig).toHaveBeenCalledTimes(1) - expect(mockGetIdentity).toHaveBeenCalledTimes(1) - expect(mockGetVersion).toHaveBeenCalledTimes(1) + waitFor(() => expect(mockGetAppConfig).toHaveBeenCalledTimes(1)) + waitFor(() => expect(mockGetIdentity).toHaveBeenCalledTimes(1)) + waitFor(() => expect(mockGetVersion).toHaveBeenCalledTimes(1)) } function expectDataNotToBeRequested() { @@ -114,12 +114,7 @@ describe('given a hook to load all the data necessary for the app to boot', () = }) it('should request the data', async () => { - const {waitForNextUpdate} = renderHook( - () => useLoadingState(), - {wrapper}, - ) - - await waitForNextUpdate() + renderHook(() => useLoadingState(), {wrapper}) expectDataToBeRequested() }) @@ -139,12 +134,7 @@ describe('given a hook to load all the data necessary for the app to boot', () = }) it('should request the data', async () => { - const {waitForNextUpdate} = renderHook( - () => useLoadingState(), - {wrapper}, - ) - - await waitForNextUpdate() + renderHook(() => useLoadingState(), {wrapper}) expectDataToBeRequested() }) @@ -166,12 +156,7 @@ describe('given a hook to load all the data necessary for the app to boot', () = }) it('should request the data', async () => { - const {waitForNextUpdate} = renderHook( - () => useLoadingState(), - {wrapper}, - ) - - await waitForNextUpdate() + renderHook(() => useLoadingState(), {wrapper}) expectDataToBeRequested() }) @@ -259,10 +244,9 @@ describe('given a hook to load all the data necessary for the app to boot', () = done() }) - const {waitForNextUpdate} = renderHook(() => useLoadingState(<>), { + renderHook(() => useLoadingState(<>), { wrapper, }) - waitForNextUpdate() }) }) })