redux-devtools/packages/redux-devtools-ui/tests/Editor.test.tsx
Nathan Bierema 57ec0534b2
Replace enzyme with React testing library in ui (#917)
* Replace enzyme with React testing library in ui

* Mock Math.random()
2021-10-22 04:18:03 +00:00

41 lines
999 B
TypeScript

import React from 'react';
import { render } from '@testing-library/react';
import { Editor } from '../src';
import 'codemirror/mode/javascript/javascript';
describe('Editor', function () {
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(),
};
};
return range;
};
const { container } = render(<Editor value="var a = 1;" />);
it('renders correctly', () => {
expect(container.firstChild).toMatchSnapshot();
});
it('calls getBoundingClientRect', () => {
expect(getBoundingClientRect).toHaveBeenCalled();
});
it('calls getClientRects', () => {
expect(getClientRects).toHaveBeenCalled();
});
});