From bc62d4a09005a827cef9f551becfc6b8540edbb4 Mon Sep 17 00:00:00 2001 From: Thomas Roest Date: Wed, 5 Oct 2022 13:59:00 +0200 Subject: [PATCH] Fix: fix failing Editor test 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. --- src/client/rsg-components/Editor/Editor.spec.tsx | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/client/rsg-components/Editor/Editor.spec.tsx b/src/client/rsg-components/Editor/Editor.spec.tsx index 4ce518e7d..3f1c012de 100644 --- a/src/client/rsg-components/Editor/Editor.spec.tsx +++ b/src/client/rsg-components/Editor/Editor.spec.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import { fireEvent, render } from '@testing-library/react'; import { shallow, mount } from 'enzyme'; import { Editor } from './Editor'; @@ -9,7 +10,6 @@ const props = { onChange() {}, code, }; - describe('Editor', () => { it('should renderer and editor', () => { const actual = shallow(); @@ -27,16 +27,10 @@ describe('Editor', () => { it('should call onChange when textarea value changes', () => { const onChange = jest.fn(); - const actual = mount(); - - expect(actual.text()).toMatch(code); + const { getByText } = render(); - // 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); });