Skip to content

Commit

Permalink
Fix: fix failing Editor test
Browse files Browse the repository at this point in the history
Enzyme 'simulate' does not seem to work correctly after upgrading react and react simple code editor.
The tests works as expected when replacing enzyme mount and simulate with React testing library implementations.
  • Loading branch information
Thomas Roest committed Oct 6, 2022
1 parent 0189c07 commit 4abad5f
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/client/rsg-components/Editor/Editor.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { fireEvent, render } from '@testing-library/react';
import { shallow, mount } from 'enzyme';
import { Editor } from './Editor';

Expand All @@ -9,7 +10,6 @@ const props = {
onChange() {},
code,
};

describe('Editor', () => {
it('should renderer and editor', () => {
const actual = shallow(<Editor {...props} />);
Expand All @@ -27,16 +27,10 @@ describe('Editor', () => {

it('should call onChange when textarea value changes', () => {
const onChange = jest.fn();
const actual = mount(<Editor {...props} onChange={onChange} />);

expect(actual.text()).toMatch(code);
const { getByText } = render(<Editor {...props} onChange={onChange} />);

// Set new value
actual.find('textarea').simulate('change', {
target: {
value: newCode,
},
});
const textarea = getByText(code);
fireEvent.change(textarea, { target: { value: newCode } });

expect(onChange).toBeCalledWith(newCode);
});
Expand Down

0 comments on commit 4abad5f

Please sign in to comment.