Skip to content

Commit 1eb4cc8

Browse files
test: fix test code improperly using/missing 'await'
1 parent 82a3c28 commit 1eb4cc8

33 files changed

Lines changed: 126 additions & 141 deletions

File tree

src/advanced-settings/setting-card/SettingCard.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('<SettingCard />', () => {
8686
await waitFor(() => {
8787
expect(inputBox).toHaveValue('3, 2, 1');
8888
});
89-
await (async () => {
89+
await waitFor(() => {
9090
expect(setEdited).toHaveBeenCalled();
9191
expect(handleBlur).toHaveBeenCalled();
9292
});

src/certificates/certificate-details/CertificateDetailsForm.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('CertificateDetails', () => {
6565

6666
await user.type(input, newInputValue);
6767

68-
waitFor(() => {
68+
await waitFor(() => {
6969
expect(input.value).toBe(newInputValue);
7070
});
7171
});

src/certificates/certificate-signatories/CertificateSignatories.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe('CertificateSignatories', () => {
105105

106106
await user.click(deleteIcons[0]);
107107

108-
waitFor(() => {
108+
await waitFor(() => {
109109
expect(mockArrayHelpers.remove).toHaveBeenCalledWith(0);
110110
});
111111
});

src/certificates/certificate-signatories/signatory/SignatoryForm.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('Signatory Component', () => {
6868

6969
await user.type(input, newInputValue, { name: 'signatories[0].name' });
7070

71-
waitFor(() => {
71+
await waitFor(() => {
7272
expect(handleChange).toHaveBeenCalledWith(expect.anything());
7373
expect(input.value).toBe(newInputValue);
7474
});

src/certificates/layout/header-buttons/HeaderButtons.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('HeaderButtons Component', () => {
6262
const dropdownButton = getByRole('button', { name: certificatesDataMock.courseModes[0] });
6363
await user.click(dropdownButton);
6464

65-
const verifiedMode = await getByRole('button', { name: certificatesDataMock.courseModes[1] });
65+
const verifiedMode = getByRole('button', { name: certificatesDataMock.courseModes[1] });
6666
await user.click(verifiedMode);
6767

6868
await waitFor(() => {

src/course-libraries/CourseLibraries.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('<CourseLibraries />', () => {
114114
const dismissBtn = await screen.findByRole('button', { name: 'Dismiss' });
115115
await user.click(dismissBtn);
116116
expect(allTab).toHaveAttribute('aria-selected', 'true');
117-
waitFor(() => expect(alert).not.toBeInTheDocument());
117+
await waitFor(() => expect(alert).not.toBeInTheDocument());
118118
// review updates button
119119
const reviewActionBtn = await screen.findByRole('button', { name: 'Review Updates' });
120120
await user.click(reviewActionBtn);

src/course-unit/CourseUnit.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,7 @@ describe('<CourseUnit />', () => {
22182218
const currentSubSectionName = courseSectionVerticalMock.xblock_info.ancestor_info.ancestors[1].display_name;
22192219
const helpLinkUrl = 'https://edx.readthedocs.io/projects/open-edx-building-and-running-a-course/en/latest/developing_course/course_components.html#components-that-contain-other-components';
22202220

2221-
waitFor(() => {
2221+
await waitFor(() => {
22222222
const unitHeaderTitle = screen.getByTestId('unit-header-title');
22232223
expect(screen.getByText(unitDisplayName)).toBeInTheDocument();
22242224
expect(within(unitHeaderTitle).getByRole('button', { name: headerTitleMessages.altButtonEdit.defaultMessage })).toBeInTheDocument();
@@ -2321,7 +2321,7 @@ describe('<CourseUnit />', () => {
23212321
});
23222322
});
23232323

2324-
waitFor(() => {
2324+
await waitFor(() => {
23252325
simulatePostMessageEvent(messageTypes.duplicateXBlock, {});
23262326
simulatePostMessageEvent(messageTypes.newXBlockEditor, {});
23272327
expect(mockedUsedNavigate)

src/editors/data/services/cms/api.test.ts

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ describe('cms api', () => {
4848
});
4949
describe('apiMethods', () => {
5050
describe('fetchBlockId', () => {
51-
it('should call get with url.blocks', () => {
52-
apiMethods.fetchBlockById({ blockId, studioEndpointUrl });
51+
it('should call get with url.blocks', async () => {
52+
await apiMethods.fetchBlockById({ blockId, studioEndpointUrl });
5353
expect(get).toHaveBeenCalledWith(urls.block({ blockId, studioEndpointUrl }));
5454
});
5555
});
5656

5757
describe('fetchByUnitId', () => {
58-
it('should call get with url.blockAncestor', () => {
59-
apiMethods.fetchByUnitId({ blockId, studioEndpointUrl });
58+
it('should call get with url.blockAncestor', async () => {
59+
await apiMethods.fetchByUnitId({ blockId, studioEndpointUrl });
6060
expect(get).toHaveBeenCalledWith(urls.blockAncestor({ studioEndpointUrl, blockId }), {});
6161
});
6262

@@ -82,7 +82,7 @@ describe('cms api', () => {
8282
// eslint-disable-next-line no-shadow, @typescript-eslint/no-shadow
8383
const utils = await import('./utils');
8484
const getSpy = jest.spyOn(utils, 'get');
85-
apiMethods.fetchByUnitId({ blockId, studioEndpointUrl });
85+
await apiMethods.fetchByUnitId({ blockId, studioEndpointUrl });
8686
expect(getSpy).toHaveBeenCalledWith(urls.blockAncestor({ studioEndpointUrl, blockId }), {});
8787
});
8888

@@ -94,22 +94,22 @@ describe('cms api', () => {
9494
// eslint-disable-next-line no-shadow, @typescript-eslint/no-shadow
9595
const utils = await import('./utils');
9696
const getSpy = jest.spyOn(utils, 'get');
97-
apiMethods.fetchByUnitId({ blockId, studioEndpointUrl });
97+
await apiMethods.fetchByUnitId({ blockId, studioEndpointUrl });
9898
expect(getSpy).toHaveBeenCalledWith(urls.blockAncestor({ studioEndpointUrl, blockId }), {});
9999
});
100100
});
101101
});
102102

103103
describe('fetchStudioView', () => {
104-
it('should call get with url.blockStudioView', () => {
105-
apiMethods.fetchStudioView({ blockId, studioEndpointUrl });
104+
it('should call get with url.blockStudioView', async () => {
105+
await apiMethods.fetchStudioView({ blockId, studioEndpointUrl });
106106
expect(get).toHaveBeenCalledWith(urls.blockStudioView({ studioEndpointUrl, blockId }));
107107
});
108108
});
109109

110110
describe('fetchCourseImages', () => {
111-
it('should call get with url.courseAssets', () => {
112-
apiMethods.fetchCourseImages({
111+
it('should call get with url.courseAssets', async () => {
112+
await apiMethods.fetchCourseImages({
113113
learningContextId, studioEndpointUrl, pageNumber: 0,
114114
});
115115
const params = {
@@ -123,8 +123,8 @@ describe('cms api', () => {
123123
});
124124
});
125125
describe('fetchLibraryImages', () => {
126-
it('should call get with urls.libraryAssets for library V2', () => {
127-
apiMethods.fetchLibraryImages({
126+
it('should call get with urls.libraryAssets for library V2', async () => {
127+
await apiMethods.fetchLibraryImages({
128128
blockId,
129129
});
130130
expect(get).toHaveBeenCalledWith(
@@ -134,30 +134,30 @@ describe('cms api', () => {
134134
});
135135

136136
describe('fetchCourseDetails', () => {
137-
it('should call get with url.courseDetailsUrl', () => {
138-
apiMethods.fetchCourseDetails({ learningContextId, studioEndpointUrl });
137+
it('should call get with url.courseDetailsUrl', async () => {
138+
await apiMethods.fetchCourseDetails({ learningContextId, studioEndpointUrl });
139139
expect(get).toHaveBeenCalledWith(urls.courseDetailsUrl({ studioEndpointUrl, learningContextId }));
140140
});
141141
});
142142

143143
describe('fetchVideos', () => {
144-
it('should call get with url.courseVideos', () => {
145-
apiMethods.fetchVideos({ learningContextId, studioEndpointUrl });
144+
it('should call get with url.courseVideos', async () => {
145+
await apiMethods.fetchVideos({ learningContextId, studioEndpointUrl });
146146
expect(get).toHaveBeenCalledWith(urls.courseVideos({ studioEndpointUrl, learningContextId }));
147147
});
148148
});
149149

150150
describe('fetchAdvancedSettings', () => {
151-
it('should call get with url.courseAdvanceSettings', () => {
152-
apiMethods.fetchAdvancedSettings({ learningContextId, studioEndpointUrl });
151+
it('should call get with url.courseAdvanceSettings', async () => {
152+
await apiMethods.fetchAdvancedSettings({ learningContextId, studioEndpointUrl });
153153
expect(get).toHaveBeenCalledWith(urls.courseAdvanceSettings({ studioEndpointUrl, learningContextId }));
154154
});
155155
});
156156

157157
describe('getHandlerUrl', () => {
158-
it('should call get with url.handlerUrl', () => {
158+
it('should call get with url.handlerUrl', async () => {
159159
const handlerName = 'transcript';
160-
apiMethods.getHandlerUrl({ studioEndpointUrl, blockId, handlerName });
160+
await apiMethods.getHandlerUrl({ studioEndpointUrl, blockId, handlerName });
161161
expect(get).toHaveBeenCalledWith(urls.handlerUrl({ studioEndpointUrl, blockId, handlerName }));
162162
});
163163
});
@@ -250,8 +250,8 @@ describe('cms api', () => {
250250

251251
describe('saveBlock', () => {
252252
const content = 'Im baby palo santo ugh celiac fashion axe. La croix lo-fi venmo whatever. Beard man braid migas single-origin coffee forage ramps.';
253-
it('should call post with urls.block and normalizeContent', () => {
254-
apiMethods.saveBlock({
253+
it('should call post with urls.block and normalizeContent', async () => {
254+
await apiMethods.saveBlock({
255255
blockId,
256256
blockType: 'html',
257257
content,
@@ -278,8 +278,8 @@ describe('cms api', () => {
278278
const asset = new File([img], filename, { type: 'image/jpeg' });
279279
const mockFormdata = new FormData();
280280
mockFormdata.append('file', asset);
281-
it('should call post with urls.courseAssets and imgdata', () => {
282-
apiMethods.uploadAsset({
281+
it('should call post with urls.courseAssets and imgdata', async () => {
282+
await apiMethods.uploadAsset({
283283
blockId,
284284
learningContextId,
285285
studioEndpointUrl,
@@ -290,10 +290,10 @@ describe('cms api', () => {
290290
mockFormdata,
291291
);
292292
});
293-
it('should call post with urls.libraryAssets and imgdata', () => {
293+
it('should call post with urls.libraryAssets and imgdata', async () => {
294294
learningContextId = 'lib:demo2uX';
295295
mockFormdata.append('content', asset);
296-
apiMethods.uploadAsset({
296+
await apiMethods.uploadAsset({
297297
blockId,
298298
learningContextId,
299299
studioEndpointUrl,
@@ -307,10 +307,10 @@ describe('cms api', () => {
307307
});
308308

309309
describe('uploadVideo', () => {
310-
it('should call post with urls.courseVideos and data', () => {
310+
it('should call post with urls.courseVideos and data', async () => {
311311
const data = { files: [{ file_name: 'video.mp4', content_type: 'mp4' }] };
312312

313-
apiMethods.uploadVideo({ data, studioEndpointUrl, learningContextId });
313+
await apiMethods.uploadVideo({ data, studioEndpointUrl, learningContextId });
314314

315315
expect(urls.courseVideos).toHaveBeenCalledWith({ studioEndpointUrl, learningContextId });
316316
expect(post).toHaveBeenCalledWith(
@@ -354,10 +354,10 @@ describe('cms api', () => {
354354
describe('uploadThumbnail', () => {
355355
const thumbnail = 'dAta';
356356
const videoId = 'sOmeVIDeoiD';
357-
it('should call post with urls.thumbnailUpload and thumbnail data', () => {
357+
it('should call post with urls.thumbnailUpload and thumbnail data', async () => {
358358
const mockFormdata = new FormData();
359359
mockFormdata.append('file', thumbnail);
360-
apiMethods.uploadThumbnail({
360+
await apiMethods.uploadThumbnail({
361361
studioEndpointUrl,
362362
learningContextId,
363363
videoId,
@@ -376,8 +376,8 @@ describe('cms api', () => {
376376
const youTubeId = 'SOMeyoutUBeid';
377377
describe('checkTranscriptsForImport', () => {
378378
const getJSON = `{"locator":"${blockId}","videos":[{"mode":"youtube","video":"${youTubeId}","type":"youtube"},{"mode":"edx_video_id","type":"edx_video_id","video":"${videoId}"}]}`;
379-
it('should call get with url.checkTranscriptsForImport', () => {
380-
apiMethods.checkTranscriptsForImport({
379+
it('should call get with url.checkTranscriptsForImport', async () => {
380+
await apiMethods.checkTranscriptsForImport({
381381
studioEndpointUrl,
382382
blockId,
383383
videoId,
@@ -391,8 +391,8 @@ describe('cms api', () => {
391391
});
392392
describe('importTranscript', () => {
393393
const getJSON = `{"locator":"${blockId}","videos":[{"mode":"youtube","video":"${youTubeId}","type":"youtube"}]}`;
394-
it('should call get with url.replaceTranscript', () => {
395-
apiMethods.importTranscript({ studioEndpointUrl, blockId, youTubeId });
394+
it('should call get with url.replaceTranscript', async () => {
395+
await apiMethods.importTranscript({ studioEndpointUrl, blockId, youTubeId });
396396
expect(get).toHaveBeenCalledWith(urls.replaceTranscript({
397397
studioEndpointUrl,
398398
parameters: encodeURIComponent(getJSON),
@@ -401,13 +401,13 @@ describe('cms api', () => {
401401
});
402402
describe('uploadTranscript', () => {
403403
const transcript = new Blob(['dAta']);
404-
it('should call post with urls.videoTranscripts and transcript data', () => {
404+
it('should call post with urls.videoTranscripts and transcript data', async () => {
405405
const mockFormdata = new FormData();
406406
mockFormdata.append('file', transcript);
407407
mockFormdata.append('edx_video_id', videoId);
408408
mockFormdata.append('language_code', language);
409409
mockFormdata.append('new_language_code', language);
410-
apiMethods.uploadTranscript({
410+
await apiMethods.uploadTranscript({
411411
blockId,
412412
studioEndpointUrl,
413413
transcript,
@@ -422,14 +422,14 @@ describe('cms api', () => {
422422
});
423423
describe('uploadTranscriptV2', () => {
424424
const transcript = new Blob(['dAta']);
425-
it('should call post with urls.uploadTranscriptV2 and transcript data', () => {
425+
it('should call post with urls.uploadTranscriptV2 and transcript data', async () => {
426426
const mockFormdata = new FormData();
427427
const transcriptHandlerUrl = 'handlerUrl';
428428
mockFormdata.append('file', transcript);
429429
mockFormdata.append('edx_video_id', videoId);
430430
mockFormdata.append('language_code', language);
431431
mockFormdata.append('new_language_code', language);
432-
apiMethods.uploadTranscriptV2({
432+
await apiMethods.uploadTranscriptV2({
433433
handlerUrl: transcriptHandlerUrl,
434434
transcript,
435435
videoId,
@@ -442,9 +442,9 @@ describe('cms api', () => {
442442
});
443443
});
444444
describe('transcript delete', () => {
445-
it('should call deleteObject with urls.videoTranscripts and transcript data', () => {
445+
it('should call deleteObject with urls.videoTranscripts and transcript data', async () => {
446446
const mockDeleteJSON = { data: { lang: language, edx_video_id: videoId } };
447-
apiMethods.deleteTranscript({
447+
await apiMethods.deleteTranscript({
448448
blockId,
449449
studioEndpointUrl,
450450
videoId,
@@ -455,10 +455,10 @@ describe('cms api', () => {
455455
mockDeleteJSON,
456456
);
457457
});
458-
it('should call deleteObject with urls.transcriptXblockV2 and transcript data', () => {
458+
it('should call deleteObject with urls.transcriptXblockV2 and transcript data', async () => {
459459
const mockDeleteJSON = { data: { lang: language, edx_video_id: videoId } };
460460
const transcriptHandlerUrl = 'handlerUrl';
461-
apiMethods.deleteTranscriptV2({
461+
await apiMethods.deleteTranscriptV2({
462462
handlerUrl: transcriptHandlerUrl,
463463
videoId,
464464
language,
@@ -483,10 +483,10 @@ describe('cms api', () => {
483483
mockJSON,
484484
);
485485
});
486-
it('should call get with urls.transcriptXblockV2 and transcript data', () => {
486+
it('should call get with urls.transcriptXblockV2 and transcript data', async () => {
487487
const mockJSON = { data: { lang: language, edx_video_id: videoId } };
488488
const transcriptHandlerUrl = 'handlerUrl';
489-
apiMethods.getTranscriptV2({
489+
await apiMethods.getTranscriptV2({
490490
handlerUrl: transcriptHandlerUrl,
491491
videoId,
492492
language,
@@ -672,9 +672,9 @@ describe('cms api', () => {
672672
});
673673
});
674674
describe('fetchVideoFeatures', () => {
675-
it('should call get with url.videoFeatures', () => {
675+
it('should call get with url.videoFeatures', async () => {
676676
const args = { studioEndpointUrl };
677-
apiMethods.fetchVideoFeatures({ ...args });
677+
await apiMethods.fetchVideoFeatures({ ...args });
678678
expect(get).toHaveBeenCalledWith(urls.videoFeatures({ ...args }));
679679
});
680680
});

src/editors/sharedComponents/SelectableBox/tests/SelectableBox.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('<SelectableBox />', () => {
7777
const onClickSpy = jest.fn();
7878
render(<SelectableCheckbox onClick={onClickSpy} />);
7979
const selectableBox = screen.getByRole('button');
80-
await await user.click(selectableBox);
80+
await user.click(selectableBox);
8181
expect(onClickSpy).toHaveBeenCalledTimes(1);
8282
});
8383
it('renders with on key press event when onClick is passed', async () => {
@@ -86,7 +86,7 @@ describe('<SelectableBox />', () => {
8686
render(<SelectableCheckbox onClick={onClickSpy} />);
8787
const selectableBox = screen.getByRole('button');
8888
selectableBox.focus();
89-
await await user.keyboard('{enter}');
89+
await user.keyboard('{enter}');
9090
expect(onClickSpy).toHaveBeenCalledTimes(1);
9191
});
9292
it('renders with hidden input when inputHidden is passed', () => {

src/editors/sharedComponents/SelectableBox/tests/SelectableBoxSet.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('<SelectableBox.Set />', () => {
6868
const onChangeSpy = jest.fn();
6969
render(<SelectableCheckboxSet onChange={onChangeSpy} />);
7070
const checkbox = screen.getByRole('button', { name: checkboxText(1) });
71-
await await user.click(checkbox);
71+
await user.click(checkbox);
7272
expect(onChangeSpy).toHaveBeenCalledTimes(1);
7373
});
7474
it('renders with checkbox type', () => {

0 commit comments

Comments
 (0)