import { shallow } from 'enzyme'; import 'jest-enzyme'; import * as React from 'react'; import { JSONSchema4 } from 'json-schema'; import { JsonSchemaViewer, SchemaTree } from '../../components'; import { isSchemaViewerEmpty } from '../../utils/isSchemaViewerEmpty'; jest.mock('../../utils/isSchemaViewerEmpty'); jest.mock('../../components/SchemaTree', () => ({ SchemaTree() { return
; }, })); const schema: JSONSchema4 = { properties: { data: { items: { $ref: '#/definitions/Gif', }, type: 'array', }, meta: { $ref: '#/definitions/Meta', }, pagination: { $ref: '#/definitions/Pagination', }, }, }; describe('JSON Schema Viewer component', () => { beforeEach(() => { (isSchemaViewerEmpty as jest.Mock).mockReturnValue(false); }); test('should render empty message if schema is empty', () => { (isSchemaViewerEmpty as jest.Mock).mockReturnValue(true); const wrapper = shallow() .dive() .dive(); expect(isSchemaViewerEmpty).toHaveBeenCalledWith({}); expect(wrapper.find(SchemaTree)).not.toExist(); }); test('should render SchemaView if schema is provided', () => { const wrapper = shallow() .dive() .dive(); expect(isSchemaViewerEmpty).toHaveBeenCalledWith(schema); expect(wrapper.find(SchemaTree)).toExist(); }); });