redux-devtools/packages/devui/tests/Editor.test.tsx

49 lines
1.0 KiB
TypeScript
Raw Normal View History

2019-01-03 16:00:55 +03:00
import React from 'react';
import { mount } from 'enzyme';
import { mountToJson } from 'enzyme-to-json';
import { Editor } from '../src';
import 'codemirror/mode/javascript/javascript';
describe('Editor', function () {
2019-01-03 16:00:55 +03:00
const getBoundingClientRect = jest.fn();
const getClientRects = jest.fn();
// See https://github.com/jsdom/jsdom/issues/3002
document.createRange = () => {
const range = new Range();
range.getBoundingClientRect = getBoundingClientRect;
range.getClientRects = () => {
getClientRects();
return {
item: () => null,
length: 0,
[Symbol.iterator]: jest.fn(),
};
2019-01-03 16:00:55 +03:00
};
return range;
2019-01-03 16:00:55 +03:00
};
const wrapper = mount(
<Editor
value="var a = 1;"
onChange={() => {
//noop
}}
/>
);
2019-01-03 16:00:55 +03:00
it('renders correctly', () => {
expect(mountToJson(wrapper)).toMatchSnapshot();
});
it('calls getBoundingClientRect', () => {
expect(getBoundingClientRect).toBeCalled();
});
it('calls getClientRects', () => {
expect(getClientRects).toBeCalled();
});
});