Merge pull request #10935 from jakemcdermott/remove-sleep

Remove sleep from tests
This commit is contained in:
Jake McDermott 2021-12-08 11:14:36 -05:00 committed by GitHub
commit 9a930cbd95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 1 additions and 35 deletions

View File

@ -6,7 +6,6 @@ import {
shallowWithContexts,
waitForElement,
} from '../../../testUtils/enzymeHelpers';
import { sleep } from '../../../testUtils/testUtils';
import SelectResourceStep from './SelectResourceStep';
describe('<SelectResourceStep />', () => {
@ -114,7 +113,6 @@ describe('<SelectResourceStep />', () => {
/>
);
});
await sleep(0);
wrapper.update();
const checkboxListItemWrapper = wrapper.find('CheckboxListItem');
expect(checkboxListItemWrapper.length).toBe(2);

View File

@ -10,7 +10,6 @@ import {
WorkflowJobTemplatesAPI,
} from 'api';
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';
import { sleep } from '../../../testUtils/testUtils';
import LaunchButton from './LaunchButton';
@ -74,7 +73,6 @@ describe('LaunchButton', () => {
const button = wrapper.find('button');
await act(() => button.prop('onClick')());
expect(JobTemplatesAPI.readLaunch).toHaveBeenCalledWith(1);
await sleep(0);
expect(JobTemplatesAPI.launch).toHaveBeenCalledWith(1, {});
expect(history.location.pathname).toEqual('/jobs/9000/output');
});
@ -111,7 +109,6 @@ describe('LaunchButton', () => {
const button = wrapper.find('button');
await act(() => button.prop('onClick')());
expect(WorkflowJobTemplatesAPI.readLaunch).toHaveBeenCalledWith(1);
await sleep(0);
expect(WorkflowJobTemplatesAPI.launch).toHaveBeenCalledWith(1, {});
expect(history.location.pathname).toEqual('/jobs/9000/output');
});
@ -128,7 +125,7 @@ describe('LaunchButton', () => {
WorkflowJobTemplatesAPI.launch.mockImplementation(async () => {
// return asynchronously so isLaunching isn't set back to false in the
// same tick
await sleep(10);
await new Promise((resolve) => setTimeout(resolve, 10));
return {
data: {
id: 9000,
@ -190,7 +187,6 @@ describe('LaunchButton', () => {
const button = wrapper.find('button');
await act(() => button.prop('onClick')());
expect(JobsAPI.readRelaunch).toHaveBeenCalledWith(1);
await sleep(0);
expect(JobsAPI.relaunch).toHaveBeenCalledWith(1, {});
expect(history.location.pathname).toEqual('/jobs/9000/output');
});
@ -227,7 +223,6 @@ describe('LaunchButton', () => {
const button = wrapper.find('button');
await act(() => button.prop('onClick')());
expect(WorkflowJobsAPI.readRelaunch).toHaveBeenCalledWith(1);
await sleep(0);
expect(WorkflowJobsAPI.relaunch).toHaveBeenCalledWith(1);
expect(history.location.pathname).toEqual('/jobs/9000/output');
});
@ -265,7 +260,6 @@ describe('LaunchButton', () => {
const button = wrapper.find('button');
await act(() => button.prop('onClick')());
expect(ProjectsAPI.readLaunchUpdate).toHaveBeenCalledWith(5);
await sleep(0);
expect(ProjectsAPI.launchUpdate).toHaveBeenCalledWith(5);
expect(history.location.pathname).toEqual('/jobs/9000/output');
});
@ -303,7 +297,6 @@ describe('LaunchButton', () => {
const button = wrapper.find('button');
await act(() => button.prop('onClick')());
expect(InventorySourcesAPI.readLaunchUpdate).toHaveBeenCalledWith(5);
await sleep(0);
expect(InventorySourcesAPI.launchUpdate).toHaveBeenCalledWith(5);
expect(history.location.pathname).toEqual('/jobs/9000/output');
});
@ -326,11 +319,9 @@ describe('LaunchButton', () => {
);
expect(wrapper.find('Modal').length).toBe(0);
await act(() => wrapper.find('button').prop('onClick')());
await sleep(0);
wrapper.update();
expect(wrapper.find('Modal').length).toBe(1);
wrapper.find('ModalBoxCloseButton').simulate('click');
await sleep(0);
wrapper.update();
expect(wrapper.find('Modal').length).toBe(0);
});

View File

@ -6,7 +6,6 @@ import {
mountWithContexts,
waitForElement,
} from '../../../../testUtils/enzymeHelpers';
import { sleep } from '../../../../testUtils/testUtils';
import InventoryAdd from './InventoryAdd';
@ -43,7 +42,6 @@ describe('<InventoryAdd />', () => {
instanceGroups,
});
});
await sleep(1);
expect(InventoriesAPI.create).toHaveBeenCalledWith({
name: 'new Foo',
organization: 2,

View File

@ -6,7 +6,6 @@ import {
mountWithContexts,
waitForElement,
} from '../../../../testUtils/enzymeHelpers';
import { sleep } from '../../../../testUtils/testUtils';
import InventoryEdit from './InventoryEdit';
@ -105,7 +104,6 @@ describe('<InventoryEdit />', () => {
instanceGroups,
});
});
await sleep(0);
expect(InventoriesAPI.orderInstanceGroups).toHaveBeenCalledWith(
mockInventory.id,
instanceGroups,

View File

@ -3,7 +3,6 @@ import { act } from 'react-dom/test-utils';
import { createMemoryHistory } from 'history';
import { JobsAPI, ProjectUpdatesAPI } from 'api';
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
import { sleep } from '../../../../testUtils/testUtils';
import JobDetail from './JobDetail';
import mockJobData from '../shared/data.job.json';
@ -249,7 +248,6 @@ describe('<JobDetail />', () => {
test('should properly delete job', async () => {
wrapper = mountWithContexts(<JobDetail job={mockJobData} />);
wrapper.find('button[aria-label="Delete"]').simulate('click');
await sleep(1);
wrapper.update();
const modal = wrapper.find('Modal[aria-label="Alert modal"]');
expect(modal.length).toBe(1);
@ -296,7 +294,6 @@ describe('<JobDetail />', () => {
const detail = wrapper.find('JobDetail');
async function assertMissingDetail(label) {
expect(detail.length).toBe(1);
await sleep(0);
expect(detail.find(`Detail[label="${label}"] dt`).text()).toBe(label);
expect(detail.find(`Detail[label="${label}"] dd`).text()).toBe('DELETED');
}

View File

@ -6,7 +6,6 @@ import {
mountWithContexts,
waitForElement,
} from '../../../../testUtils/enzymeHelpers';
import { sleep } from '../../../../testUtils/testUtils';
import OrganizationTeamList from './OrganizationTeamList';
@ -100,7 +99,6 @@ describe('<OrganizationTeamList />', () => {
<OrganizationTeamList id={1} searchString="" />
);
});
await sleep(0);
wrapper.update();
const list = wrapper.find('PaginatedTable');

View File

@ -2,7 +2,6 @@ import React from 'react';
import { act } from 'react-dom/test-utils';
import { ProjectsAPI } from 'api';
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
import { sleep } from '../../../../testUtils/testUtils';
import ProjectSyncButton from './ProjectSyncButton';
@ -89,13 +88,11 @@ describe('ProjectSyncButton', () => {
await act(async () => {
wrapper.find('button').prop('onClick')();
});
await sleep(0);
wrapper.update();
expect(wrapper.find('Modal').length).toBe(1);
await act(async () => {
wrapper.find('ModalBoxCloseButton').simulate('click');
});
await sleep(0);
wrapper.update();
expect(wrapper.find('Modal').length).toBe(0);
});

View File

@ -15,7 +15,6 @@ import {
mountWithContexts,
waitForElement,
} from '../../../../testUtils/enzymeHelpers';
import { sleep } from '../../../../testUtils/testUtils';
import JobTemplateForm from './JobTemplateForm';
jest.mock('../../../api');
@ -420,7 +419,6 @@ describe('<JobTemplateForm />', () => {
await act(async () => {
wrapper.find('button[aria-label="Save"]').simulate('click');
});
await sleep(1);
expect(handleSubmit).toBeCalled();
});

View File

@ -12,7 +12,6 @@ import {
ExecutionEnvironmentsAPI,
CredentialsAPI,
} from 'api';
import { sleep } from '../../../../testUtils/testUtils';
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
import WorkflowJobTemplateForm from './WorkflowJobTemplateForm';
@ -310,7 +309,6 @@ describe('<WorkflowJobTemplateForm/>', () => {
wrapper.find('Formik').prop('onSubmit')({});
});
wrapper.update();
sleep(0);
expect(handleSubmit).toBeCalled();
});

View File

@ -6,7 +6,6 @@ import {
waitForElement,
} from '../../../../testUtils/enzymeHelpers';
import UserTokenForm from './UserTokenForm';
import { sleep } from '../../../../testUtils/testUtils';
jest.mock('../../../api');
const applications = {
@ -102,7 +101,6 @@ describe('<UserTokenForm />', () => {
await act(async () => {
wrapper.find('button[aria-label="Save"]').prop('onClick')();
});
await sleep(1);
expect(handleSubmit).toBeCalled();
});
@ -132,7 +130,6 @@ describe('<UserTokenForm />', () => {
await act(async () => {
wrapper.find('button[aria-label="Save"]').prop('onClick')();
});
await sleep(1);
wrapper.update();
expect(
wrapper.find('FormGroup[name="scope"]').prop('helperTextInvalid')

View File

@ -1,4 +0,0 @@
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
/* eslint-disable-next-line import/prefer-default-export */
export { sleep };