Skip to content

Commit be5b941

Browse files
chore(tests): fix generic/data/apiHooks tests
* Replaced `waitForNextUpdate` with `waitFor` (see testing-library/react-testing-library#1101) * Updated `courseId` in success/fail tests to prevent concurrency issues
1 parent 0bae556 commit be5b941

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/generic/data/apiHooks.test.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { initializeMockApp } from '@edx/frontend-platform';
33
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
44
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
5-
import { renderHook } from '@testing-library/react';
5+
import { renderHook, waitFor } from '@testing-library/react';
66
import MockAdapter from 'axios-mock-adapter';
77

88
import { getTagsCountApiUrl } from './api';
@@ -43,11 +43,14 @@ describe('useContentTagsCount', () => {
4343
});
4444

4545
it('should return success response', async () => {
46-
const courseId = 'course-v1:edX+TestX+Test_Course';
46+
const courseId = 'course-v1:edX+TestX+Test_Course_SUCCESS';
4747
axiosMock.onGet(getTagsCountApiUrl(courseId)).reply(200, { [courseId]: 10 });
4848

4949
const hook = renderHook(() => useContentTagsCount(courseId), { wrapper });
50-
await hook.waitForNextUpdate();
50+
await waitFor(() => {
51+
expect(hook.result.current.isLoading).toBeFalsy();
52+
});
53+
5154
const { data, isSuccess } = hook.result.current;
5255

5356
expect(axiosMock.history.get[0].url).toEqual(getTagsCountApiUrl(courseId));
@@ -56,12 +59,13 @@ describe('useContentTagsCount', () => {
5659
});
5760

5861
it('should return failure response', async () => {
59-
const courseId = 'course-v1:edX+TestX+Test_Course';
62+
const courseId = 'course-v1:edX+TestX+Test_Course_FAILURE';
6063
axiosMock.onGet(getTagsCountApiUrl(courseId)).reply(500, 'error');
6164

6265
const hook = renderHook(() => useContentTagsCount(courseId), { wrapper });
63-
await hook.waitForNextUpdate();
64-
66+
await waitFor(() => {
67+
expect(hook.result.current.isLoading).toBeFalsy();
68+
});
6569
const { isSuccess } = hook.result.current;
6670

6771
expect(axiosMock.history.get[0].url).toEqual(getTagsCountApiUrl(courseId));
@@ -77,7 +81,9 @@ describe('useContentTagsCount', () => {
7781
});
7882

7983
const hook = renderHook(() => useContentTagsCount(blockId), { wrapper });
80-
await hook.waitForNextUpdate();
84+
await waitFor(() => {
85+
expect(hook.result.current.isLoading).toBeFalsy();
86+
});
8187

8288
const { data, isSuccess } = hook.result.current;
8389

0 commit comments

Comments
 (0)