Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: add missing await for async statements in tests #5871

Merged
merged 2 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('test DueDate', () => {
</ReduxIntlProviders>,
);
expect(screen.queryByText('Tooltip works')).not.toBeInTheDocument();
userEvent.hover(screen.getByText('5 days left'));
await userEvent.hover(screen.getByText('5 days left'));
await waitFor(() => expect(screen.getByText('Tooltip works')).toBeInTheDocument());
expect(screen.getByText('Tooltip works')).toBeInTheDocument();
expect(container.querySelectorAll('span')[0].className).toContain('bg-tan blue-grey');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ describe('MoreFiltersForm', () => {

expect(switchControl).toBeInTheDocument();
await userEvent.click(switchControl);
waitFor(() =>
await waitFor(() =>
expect(
decodeQueryParams(
{
basedOnMyInterests: BooleanParam,
},
parse(router.state.location.search),
),
).toEqual({ basedOnMyInterests: 1 }),
).toEqual({ basedOnMyInterests: true }),
);
});

Expand Down
16 changes: 8 additions & 8 deletions frontend/src/components/taskSelection/tests/footer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('Footer Lock Tasks', () => {
});

it('should display task cannot be locked for mapping message', async () => {
clearReduxStore();
await clearReduxStore();
setupFaultyHandlers();
createComponentWithMemoryRouter(
<ReduxIntlProviders>
Expand All @@ -172,7 +172,7 @@ describe('Footer Lock Tasks', () => {
});

it('should display no mapped tasks selected message', async () => {
clearReduxStore();
await clearReduxStore();
setupFaultyHandlers();
createComponentWithMemoryRouter(
<ReduxIntlProviders>
Expand All @@ -198,7 +198,7 @@ describe('Footer Lock Tasks', () => {
});

it('should display task cannot be locked for validation message', async () => {
clearReduxStore();
await clearReduxStore();
setupFaultyHandlers();
createComponentWithMemoryRouter(
<ReduxIntlProviders>
Expand Down Expand Up @@ -295,7 +295,7 @@ describe('Footer Lock Tasks', () => {
});

it('should navigate to task action page on validating a task', async () => {
clearReduxStore();
await clearReduxStore();
const { router } = createComponentWithMemoryRouter(
<ReduxIntlProviders>
<TaskSelectionFooter
Expand All @@ -319,7 +319,7 @@ describe('Footer Lock Tasks', () => {
});

it('should resume mapping', async () => {
clearReduxStore();
await clearReduxStore();
const { router } = createComponentWithMemoryRouter(
<ReduxIntlProviders>
<TaskSelectionFooter
Expand All @@ -343,7 +343,7 @@ describe('Footer Lock Tasks', () => {
});

it('should resume validation', async () => {
clearReduxStore();
await clearReduxStore();
const { router } = createComponentWithMemoryRouter(
<ReduxIntlProviders>
<TaskSelectionFooter
Expand All @@ -367,7 +367,7 @@ describe('Footer Lock Tasks', () => {
});

it('should fallback editor when user default is not in the list for validation', async () => {
clearReduxStore();
await clearReduxStore();
const { router } = createComponentWithMemoryRouter(
<ReduxIntlProviders>
<TaskSelectionFooter
Expand All @@ -391,7 +391,7 @@ describe('Footer Lock Tasks', () => {
});

it('should fallback editor when user default is not in the list for mapping', async () => {
clearReduxStore();
await clearReduxStore();
const { router } = createComponentWithMemoryRouter(
<ReduxIntlProviders>
<TaskSelectionFooter
Expand Down
21 changes: 13 additions & 8 deletions frontend/src/views/tests/fallback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ import { FallbackComponent } from '../fallback';
import { SERVICE_DESK } from '../../config';
import messages from '../messages';

/*
* This was in "should trigger navigate on return button click". There are
* references to some things being hoisted to different locations in Jest
* documentation. For whatever reason, we have to mock it here, instead of later
* in the test where we actually need to mock it.
*/
const mockedUsedNavigate = jest.fn();
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => mockedUsedNavigate,
}));

describe('Fallback component', () => {
it('should render component details', () => {
renderWithRouter(
Expand Down Expand Up @@ -50,13 +62,6 @@ describe('Fallback component', () => {
});

it('should trigger navigate on return button click', async () => {
const mockedUsedNavigate = jest.fn();

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => mockedUsedNavigate,
}));

renderWithRouter(
<IntlProviders>
<FallbackComponent />
Expand All @@ -67,6 +72,6 @@ describe('Fallback component', () => {
name: messages.return.defaultMessage,
});
await userEvent.click(returnBtn);
waitFor(() => expect(mockedUsedNavigate).toHaveBeenCalledTimes(1));
await waitFor(() => expect(mockedUsedNavigate).toHaveBeenCalledTimes(1));
});
});
8 changes: 4 additions & 4 deletions frontend/src/views/tests/organisationManagement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ describe('Create Organization', () => {
await user.type(nameInput, 'New Organization Name');
const subscriptionType = screen.getByRole('combobox');
fireEvent.mouseDown(subscriptionType);
user.click(screen.getByText('Free'));
user.click(createButton);
await user.click(screen.getByText('Free'));
await user.click(createButton);
await waitFor(() => {
expect(toast.success).toHaveBeenCalledTimes(1);
expect(router.state.location.pathname).toBe('/manage/organisations/123');
Expand All @@ -125,8 +125,8 @@ describe('Create Organization', () => {
await user.type(nameInput, 'New Organization Name');
const subscriptionType = screen.getByRole('combobox');
fireEvent.mouseDown(subscriptionType);
user.click(screen.getByText('Free'));
user.click(createButton);
await user.click(screen.getByText('Free'));
await user.click(createButton);
await waitFor(() =>
expect(
screen.getByText(/Failed to create organization. Please try again./i),
Expand Down