diff --git a/src/plugins/data/public/search/fetch/fetch_soon.test.ts b/src/plugins/data/public/search/fetch/fetch_soon.test.ts index a8d593c8501f6..d33cb60be0dec 100644 --- a/src/plugins/data/public/search/fetch/fetch_soon.test.ts +++ b/src/plugins/data/public/search/fetch/fetch_soon.test.ts @@ -58,7 +58,7 @@ describe('fetchSoon', () => { (callClient as jest.Mock).mockClear(); }); - test('should delay by 0ms if config is set to not batch searches', () => { + test('should execute asap if config is set to not batch searches', () => { const config = getConfigStub({ 'courier:batchSearches': false, }); @@ -67,8 +67,6 @@ describe('fetchSoon', () => { fetchSoon(request, options, { config } as FetchHandlers); - expect(callClient).not.toBeCalled(); - jest.advanceTimersByTime(0); expect(callClient).toBeCalled(); }); diff --git a/src/plugins/data/public/search/fetch/fetch_soon.ts b/src/plugins/data/public/search/fetch/fetch_soon.ts index b1405747426ee..1353aab17cdab 100644 --- a/src/plugins/data/public/search/fetch/fetch_soon.ts +++ b/src/plugins/data/public/search/fetch/fetch_soon.ts @@ -67,6 +67,10 @@ async function delayedFetch( fetchHandlers: FetchHandlers, ms: number ) { + if (ms === 0) { + return callClient([request], [options], fetchHandlers)[0]; + } + const i = requestsToFetch.length; requestsToFetch = [...requestsToFetch, request]; requestOptions = [...requestOptions, options];