Skip to content

Commit 4fd10c7

Browse files
committed
Replace tick() with wait()
1 parent 4d315a2 commit 4fd10c7

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

x-pack/legacy/plugins/apm/public/components/shared/DatePicker/__test__/DatePicker.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import {
1010
UrlParamsContext,
1111
useUiFilters
1212
} from '../../../../context/UrlParamsContext';
13-
import { tick } from '../../../../utils/testHelpers';
1413
import { DatePicker } from '../index';
1514
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
1615
import { history } from '../../../../utils/history';
1716
import { mount } from 'enzyme';
1817
import { EuiSuperDatePicker } from '@elastic/eui';
1918
import { MemoryRouter } from 'react-router-dom';
19+
import { wait } from '@testing-library/react';
2020

2121
const mockHistoryPush = jest.spyOn(history, 'push');
2222
const mockRefreshTimeRange = jest.fn();
@@ -84,7 +84,7 @@ describe('DatePicker', () => {
8484
});
8585
expect(mockRefreshTimeRange).not.toHaveBeenCalled();
8686
jest.advanceTimersByTime(1000);
87-
await tick();
87+
await wait();
8888
expect(mockRefreshTimeRange).toHaveBeenCalled();
8989
wrapper.unmount();
9090
});
@@ -94,7 +94,7 @@ describe('DatePicker', () => {
9494
mountDatePicker({ refreshPaused: true, refreshInterval: 1000 });
9595
expect(mockRefreshTimeRange).not.toHaveBeenCalled();
9696
jest.advanceTimersByTime(1000);
97-
await tick();
97+
await wait();
9898
expect(mockRefreshTimeRange).not.toHaveBeenCalled();
9999
});
100100
});

x-pack/legacy/plugins/apm/public/context/UrlParamsContext/__tests__/UrlParamsContext.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { Location, History } from 'history';
1111
import { MemoryRouter, Router } from 'react-router-dom';
1212
import moment from 'moment-timezone';
1313
import { IUrlParams } from '../types';
14-
import { tick } from '../../../utils/testHelpers';
1514
import { getParsedDate } from '../helpers';
15+
import { wait } from '@testing-library/react';
1616

1717
function mountParams(location: Location) {
1818
return mount(
@@ -143,13 +143,13 @@ describe('UrlParamsContext', () => {
143143
</Router>
144144
);
145145

146-
await tick();
146+
await wait();
147147

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

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

152-
await tick();
152+
await wait();
153153

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

@@ -194,11 +194,11 @@ describe('UrlParamsContext', () => {
194194
</Router>
195195
);
196196

197-
await tick();
197+
await wait();
198198

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

201-
await tick();
201+
await wait();
202202

203203
const params = getDataFromOutput(wrapper);
204204
expect(params.start).toEqual('2000-06-14T00:00:00.000Z');

x-pack/legacy/plugins/apm/public/utils/testHelpers.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export async function getRenderedHref(Component: React.FC, location: Location) {
5858
</MemoryRouter>
5959
);
6060

61-
await tick();
6261
await waitForElement(() => el.container.querySelector('a'));
6362

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

77-
// Await this when you need to "flush" promises to immediately resolve or throw in tests
78-
export const tick = () => new Promise(resolve => setImmediate(resolve, 0));
79-
8076
export function expectTextsNotInDocument(output: any, texts: string[]) {
8177
texts.forEach(text => {
8278
try {

0 commit comments

Comments
 (0)