Skip to content

Commit

Permalink
Replace tick() with wait()
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar committed Dec 10, 2019
1 parent 4d315a2 commit 4fd10c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import {
UrlParamsContext,
useUiFilters
} from '../../../../context/UrlParamsContext';
import { tick } from '../../../../utils/testHelpers';
import { DatePicker } from '../index';
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
import { history } from '../../../../utils/history';
import { mount } from 'enzyme';
import { EuiSuperDatePicker } from '@elastic/eui';
import { MemoryRouter } from 'react-router-dom';
import { wait } from '@testing-library/react';

const mockHistoryPush = jest.spyOn(history, 'push');
const mockRefreshTimeRange = jest.fn();
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('DatePicker', () => {
});
expect(mockRefreshTimeRange).not.toHaveBeenCalled();
jest.advanceTimersByTime(1000);
await tick();
await wait();
expect(mockRefreshTimeRange).toHaveBeenCalled();
wrapper.unmount();
});
Expand All @@ -94,7 +94,7 @@ describe('DatePicker', () => {
mountDatePicker({ refreshPaused: true, refreshInterval: 1000 });
expect(mockRefreshTimeRange).not.toHaveBeenCalled();
jest.advanceTimersByTime(1000);
await tick();
await wait();
expect(mockRefreshTimeRange).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { Location, History } from 'history';
import { MemoryRouter, Router } from 'react-router-dom';
import moment from 'moment-timezone';
import { IUrlParams } from '../types';
import { tick } from '../../../utils/testHelpers';
import { getParsedDate } from '../helpers';
import { wait } from '@testing-library/react';

function mountParams(location: Location) {
return mount(
Expand Down Expand Up @@ -143,13 +143,13 @@ describe('UrlParamsContext', () => {
</Router>
);

await tick();
await wait();

expect(calls.length).toBe(1);

wrapper.find('button').simulate('click');

await tick();
await wait();

expect(calls.length).toBe(2);

Expand Down Expand Up @@ -194,11 +194,11 @@ describe('UrlParamsContext', () => {
</Router>
);

await tick();
await wait();

wrapper.find('button').simulate('click');

await tick();
await wait();

const params = getDataFromOutput(wrapper);
expect(params.start).toEqual('2000-06-14T00:00:00.000Z');
Expand Down
4 changes: 0 additions & 4 deletions x-pack/legacy/plugins/apm/public/utils/testHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export async function getRenderedHref(Component: React.FC, location: Location) {
</MemoryRouter>
);

await tick();
await waitForElement(() => el.container.querySelector('a'));

const a = el.container.querySelector('a');
Expand All @@ -74,9 +73,6 @@ export function delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

// Await this when you need to "flush" promises to immediately resolve or throw in tests
export const tick = () => new Promise(resolve => setImmediate(resolve, 0));

export function expectTextsNotInDocument(output: any, texts: string[]) {
texts.forEach(text => {
try {
Expand Down

0 comments on commit 4fd10c7

Please sign in to comment.