Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock lodash debounce to fix embedded_visualize_handler unstable tests #44592

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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, AggConfig } from '../../vis';
import { VisResponseData } from './types';

import { Inspector } from '../../inspector';
import { EmbeddedVisualizeHandler } from './embedded_visualize_handler';

Expand All @@ -48,6 +48,15 @@ describe('EmbeddedVisualizeHandler', () => {
beforeEach(() => {
jest.clearAllMocks();

jest.spyOn(_, 'debounce').mockImplementation(
// @ts-ignore
(f: Function) => {
// @ts-ignore
f.cancel = () => {};
return f;
}
);

dataLoaderParams = {
aggs: [] as AggConfig[],
filters: undefined,
Expand Down Expand Up @@ -152,29 +161,29 @@ 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 });
});

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 });
});

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 });
});
Expand Down