Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Dec 31, 2019
1 parent e7774ed commit d56a8d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,23 @@ import { mount, shallow } from 'enzyme';
import { DocViewer } from './doc_viewer';
// @ts-ignore
import { findTestSubject } from '@elastic/eui/lib/test';
import { DocViewRenderProps } from '../../doc_views/doc_views_registry';
import { getServices } from '../../../kibana_services';
import { DocViewRenderProps } from '../../doc_views/doc_views_types';

jest.mock('../../../kibana_services', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { DocViewsRegistry } = require('../../doc_views/doc_views_registry');
let registry = new DocViewsRegistry();
let registry: any[] = [];
return {
getServices: () => ({
docViewsRegistry: registry,
docViewsRegistry: {
addDocView(view: any) {
registry.push(view);
},
getDocViewsSorted() {
return registry;
},
},
resetRegistry: () => {
registry = new DocViewsRegistry();
registry = [];
},
}),
formatMsg: (x: any) => String(x),
Expand All @@ -47,8 +52,8 @@ beforeEach(() => {

test('Render <DocViewer/> with 3 different tabs', () => {
const registry = getServices().docViewsRegistry;
registry.addDocView({ order: 20, title: 'React component', component: () => <div>test</div> });
registry.addDocView({ order: 10, title: 'Render function', render: jest.fn() });
registry.addDocView({ order: 20, title: 'React component', component: () => <div>test</div> });
registry.addDocView({ order: 30, title: 'Invalid doc view' });

const renderProps = { hit: {} } as DocViewRenderProps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import { convertDirectiveToRenderFn } from './doc_views_helpers';
import { DocView, DocViewInput, ElasticSearchHit, DocViewInputFn } from './doc_views_types';
import { Chrome } from '../../kibana_services';

export { DocViewRenderProps, DocView, DocViewRenderFn } from './doc_views_types';

export class DocViewsRegistry {
private docViews: DocView[] = [];

Expand Down

0 comments on commit d56a8d8

Please sign in to comment.