diff --git a/src/legacy/ui/public/visualize/loader/embedded_visualize_handler.test.ts b/src/legacy/ui/public/visualize/loader/embedded_visualize_handler.test.ts index 2b43d47323809c..bfb945be1a59d2 100644 --- a/src/legacy/ui/public/visualize/loader/embedded_visualize_handler.test.ts +++ b/src/legacy/ui/public/visualize/loader/embedded_visualize_handler.test.ts @@ -18,11 +18,11 @@ */ import { mockDataLoaderFetch, timefilter } from './embedded_visualize_handler.test.mocks'; +import _ from 'lodash'; // @ts-ignore import MockState from '../../../../../fixtures/mock_state'; import { RequestHandlerParams, Vis } from '../../vis'; import { VisResponseData } from './types'; - import { Inspector } from '../../inspector'; import { EmbeddedVisualizeHandler } from './embedded_visualize_handler'; import { AggConfigs } from 'ui/vis/agg_configs'; @@ -49,6 +49,15 @@ describe('EmbeddedVisualizeHandler', () => { beforeEach(() => { jest.clearAllMocks(); + jest.spyOn(_, 'debounce').mockImplementation( + // @ts-ignore + (f: Function) => { + // @ts-ignore + f.cancel = () => {}; + return f; + } + ); + dataLoaderParams = { aggs: ([] as any) as AggConfigs, filters: undefined, @@ -153,9 +162,9 @@ describe('EmbeddedVisualizeHandler', () => { it('should call dataLoader.render with updated timeRange', () => { const params = { timeRange: { foo: 'bar' } }; handler.update(params); - jest.runAllTimers(); expect(mockDataLoaderFetch).toHaveBeenCalled(); - const { abortSignal, ...otherParams } = mockDataLoaderFetch.mock.calls[0][0]; + const callIndex = mockDataLoaderFetch.mock.calls.length - 1; + const { abortSignal, ...otherParams } = mockDataLoaderFetch.mock.calls[callIndex][0]; expect(abortSignal).toBeInstanceOf(AbortSignal); expect(otherParams).toEqual({ ...dataLoaderParams, ...params }); }); @@ -163,9 +172,9 @@ describe('EmbeddedVisualizeHandler', () => { it('should call dataLoader.render with updated filters', () => { const params = { filters: [{ meta: { disabled: false } }] }; handler.update(params); - jest.runAllTimers(); expect(mockDataLoaderFetch).toHaveBeenCalled(); - const { abortSignal, ...otherParams } = mockDataLoaderFetch.mock.calls[0][0]; + const callIndex = mockDataLoaderFetch.mock.calls.length - 1; + const { abortSignal, ...otherParams } = mockDataLoaderFetch.mock.calls[callIndex][0]; expect(abortSignal).toBeInstanceOf(AbortSignal); expect(otherParams).toEqual({ ...dataLoaderParams, ...params }); }); @@ -173,9 +182,9 @@ describe('EmbeddedVisualizeHandler', () => { it('should call dataLoader.render with updated query', () => { const params = { query: { foo: 'bar' } }; handler.update(params); - jest.runAllTimers(); expect(mockDataLoaderFetch).toHaveBeenCalled(); - const { abortSignal, ...otherParams } = mockDataLoaderFetch.mock.calls[0][0]; + const callIndex = mockDataLoaderFetch.mock.calls.length - 1; + const { abortSignal, ...otherParams } = mockDataLoaderFetch.mock.calls[callIndex][0]; expect(abortSignal).toBeInstanceOf(AbortSignal); expect(otherParams).toEqual({ ...dataLoaderParams, ...params }); });