Skip to content

Commit 6a07ead

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

14 files changed

Lines changed: 25 additions & 31 deletions

File tree

plugins/course-apps/ora_settings/Settings.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('ORASettings', () => {
128128
renderComponent();
129129
await mockStore({ apiStatus: 200, enabled: true });
130130

131-
waitFor(() => {
131+
await waitFor(() => {
132132
const label = screen.getByText(messages.enableFlexPeerGradeLabel.defaultMessage);
133133
const enableBadge = screen.getByTestId('enable-badge');
134134

src/course-outline/OutlineAddChildButtons.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ jest.mock('react-redux', () => ({
3333
expect(newBtn).toBeInTheDocument();
3434
const useBtn = await screen.findByRole('button', { name: `Use ${containerType} from library` });
3535
expect(useBtn).toBeInTheDocument();
36-
userEvent.click(newBtn);
37-
waitFor(() => expect(newClickHandler).toHaveBeenCalled());
38-
userEvent.click(useBtn);
39-
waitFor(() => expect(useFromLibClickHandler).toHaveBeenCalled());
36+
await userEvent.click(newBtn);
37+
await waitFor(() => expect(newClickHandler).toHaveBeenCalled());
38+
await userEvent.click(useBtn);
39+
await waitFor(() => expect(useFromLibClickHandler).toHaveBeenCalled());
4040
});
4141
});
4242
});

src/custom-pages/CustomPages.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe('CustomPages', () => {
100100
it('should update page order on drag', async () => {
101101
renderComponent();
102102
await mockStore(RequestStatus.SUCCESSFUL);
103-
const buttons = await screen.queryAllByRole('button');
103+
const buttons = screen.queryAllByRole('button');
104104
const draggableButton = buttons[9];
105105
expect(draggableButton).toBeVisible();
106106
await act(async () => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ describe('cms api', () => {
470470
});
471471
});
472472
describe('transcript get', () => {
473-
it('should call get with urls.videoTranscripts and transcript data', () => {
473+
it('should call get with urls.videoTranscripts and transcript data', async () => {
474474
const mockJSON = { data: { lang: language, edx_video_id: videoId } };
475-
apiMethods.getTranscript({
475+
await apiMethods.getTranscript({
476476
blockId,
477477
studioEndpointUrl,
478478
videoId,

src/files-and-videos/videos-page/info-sidebar/TranscriptTab.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ describe('TranscriptTab', () => {
196196
axiosMock.onDelete(`${getApiBaseUrl()}/transcript_delete/${courseId}/mOckID0/ar`).reply(204);
197197
await act(async () => {
198198
fireEvent.click(confirmButton);
199-
executeThunk(deleteVideoTranscript({
199+
await executeThunk(deleteVideoTranscript({
200200
language: 'ar',
201201
videoId: updatedProps.id,
202202
transcripts: updatedProps.transcripts,
@@ -215,7 +215,7 @@ describe('TranscriptTab', () => {
215215
axiosMock.onDelete(`${getApiBaseUrl()}/transcript_delete/${courseId}/mOckID0/ar`).reply(404);
216216
await act(async () => {
217217
fireEvent.click(confirmButton);
218-
executeThunk(deleteVideoTranscript({
218+
await executeThunk(deleteVideoTranscript({
219219
language: 'ar',
220220
videoId: updatedProps.id,
221221
transcripts: updatedProps.transcripts,

src/generic/course-upload-image/CourseUploadImage.test.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { AppProvider } from '@edx/frontend-platform/react';
3-
import { fireEvent, render, act } from '@testing-library/react';
3+
import { fireEvent, render } from '@testing-library/react';
44
import { initializeMockApp } from '@edx/frontend-platform';
55
import { IntlProvider } from '@edx/frontend-platform/i18n';
66

@@ -57,9 +57,7 @@ describe('<CourseUploadImage />', () => {
5757
it('should call onChange if input value changed', async () => {
5858
const { getByPlaceholderText } = render(<RootWrapper {...props} />);
5959
const input = getByPlaceholderText(props.customInputPlaceholder);
60-
await act(() => {
61-
fireEvent.change(input, { target: { value: '/assets' } });
62-
});
60+
fireEvent.change(input, { target: { value: '/assets' } });
6361
expect(onChangeMock).toHaveBeenCalledWith(
6462
'/assets',
6563
props.assetImageField,

src/library-authoring/containers/ContainerCard.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ describe('<ContainerCard />', () => {
486486
// Click on Copy Item
487487
const copyMenuItem = screen.getByRole('button', { name: 'Copy to clipboard' });
488488
expect(copyMenuItem).toBeInTheDocument();
489-
user.click(copyMenuItem);
489+
await user.click(copyMenuItem);
490490

491491
await waitFor(() => {
492492
expect(axiosMock.history.post.length).toBe(1);

src/library-authoring/containers/ContainerInfo.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ let mockShowToast: { (message: string, action?: ToastActionData | undefined): vo
211211
// Click on Copy Item
212212
const copyMenuItem = await screen.findByRole('button', { name: 'Copy to clipboard' });
213213
expect(copyMenuItem).toBeInTheDocument();
214-
user.click(copyMenuItem);
214+
await user.click(copyMenuItem);
215215

216216
await waitFor(() => {
217217
expect(axiosMock.history.post.length).toBe(1);

src/pages-and-resources/pages/PageCard.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ describe('LiveSettings', () => {
6060

6161
it('should render three cards', async () => {
6262
renderComponent();
63-
waitFor(() => {
63+
await waitFor(() => {
6464
expect(screen.queryAllByRole(container, 'button')).toHaveLength(3);
6565
});
6666
});
6767

6868
it('should navigate to legacyLink', async () => {
6969
renderComponent();
7070
const textbookPagePath = mockPageConfig[0][1];
71-
waitFor(() => {
71+
await waitFor(() => {
7272
const textbookSettingsButton = screen.queryAllByRole(container, 'link')[1];
7373
expect(textbookSettingsButton).toHaveAttribute('href', textbookPagePath);
7474
});

src/schedule-and-details/details-section/DetailsSection.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('<DetailsSection />', () => {
3232
).toBeInTheDocument();
3333
});
3434

35-
it('should call onChange if dropdown value changed', () => {
35+
it('should call onChange if dropdown value changed', async () => {
3636
const { getByRole } = render(<RootWrapper {...props} />);
3737
const option = getByRole('button', {
3838
name: courseSettingsMock.languageOptions[1][1],
@@ -42,7 +42,7 @@ describe('<DetailsSection />', () => {
4242
name: courseSettingsMock.languageOptions[0][1],
4343
});
4444

45-
waitFor(() => expect(anotherOption));
45+
await waitFor(() => expect(anotherOption));
4646
fireEvent.click(anotherOption);
4747
expect(onChangeMock).toHaveBeenCalledWith(
4848
courseSettingsMock.languageOptions[0][0],

0 commit comments

Comments
 (0)