@@ -2,7 +2,7 @@ import React from 'react';
2
2
import { initializeMockApp } from '@edx/frontend-platform' ;
3
3
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth' ;
4
4
import { QueryClient , QueryClientProvider } from '@tanstack/react-query' ;
5
- import { renderHook } from '@testing-library/react' ;
5
+ import { renderHook , waitFor } from '@testing-library/react' ;
6
6
import MockAdapter from 'axios-mock-adapter' ;
7
7
8
8
import { getTagsCountApiUrl } from './api' ;
@@ -43,11 +43,14 @@ describe('useContentTagsCount', () => {
43
43
} ) ;
44
44
45
45
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 ' ;
47
47
axiosMock . onGet ( getTagsCountApiUrl ( courseId ) ) . reply ( 200 , { [ courseId ] : 10 } ) ;
48
48
49
49
const hook = renderHook ( ( ) => useContentTagsCount ( courseId ) , { wrapper } ) ;
50
- await hook . waitForNextUpdate ( ) ;
50
+ await waitFor ( ( ) => {
51
+ expect ( hook . result . current . isLoading ) . toBeFalsy ( ) ;
52
+ } ) ;
53
+
51
54
const { data, isSuccess } = hook . result . current ;
52
55
53
56
expect ( axiosMock . history . get [ 0 ] . url ) . toEqual ( getTagsCountApiUrl ( courseId ) ) ;
@@ -56,12 +59,13 @@ describe('useContentTagsCount', () => {
56
59
} ) ;
57
60
58
61
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 ' ;
60
63
axiosMock . onGet ( getTagsCountApiUrl ( courseId ) ) . reply ( 500 , 'error' ) ;
61
64
62
65
const hook = renderHook ( ( ) => useContentTagsCount ( courseId ) , { wrapper } ) ;
63
- await hook . waitForNextUpdate ( ) ;
64
-
66
+ await waitFor ( ( ) => {
67
+ expect ( hook . result . current . isLoading ) . toBeFalsy ( ) ;
68
+ } ) ;
65
69
const { isSuccess } = hook . result . current ;
66
70
67
71
expect ( axiosMock . history . get [ 0 ] . url ) . toEqual ( getTagsCountApiUrl ( courseId ) ) ;
@@ -77,7 +81,9 @@ describe('useContentTagsCount', () => {
77
81
} ) ;
78
82
79
83
const hook = renderHook ( ( ) => useContentTagsCount ( blockId ) , { wrapper } ) ;
80
- await hook . waitForNextUpdate ( ) ;
84
+ await waitFor ( ( ) => {
85
+ expect ( hook . result . current . isLoading ) . toBeFalsy ( ) ;
86
+ } ) ;
81
87
82
88
const { data, isSuccess } = hook . result . current ;
83
89
0 commit comments