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

41 lines
999 B
TypeScript
Raw Normal View History

2019-01-03 16:00:55 +03:00
import React from 'react';
import { render } from '@testing-library/react';
2019-01-03 16:00:55 +03:00
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 { container } = render(<Editor value="var a = 1;" />);
2019-01-03 16:00:55 +03:00
it('renders correctly', () => {
expect(container.firstChild).toMatchSnapshot();
2019-01-03 16:00:55 +03:00
});
it('calls getBoundingClientRect', () => {
expect(getBoundingClientRect).toHaveBeenCalled();
2019-01-03 16:00:55 +03:00
});
it('calls getClientRects', () => {
expect(getClientRects).toHaveBeenCalled();
2019-01-03 16:00:55 +03:00
});
});