trigger react-ace onChange via React Testing Library (RTL)
See original GitHub issueProblem
in my code, i have component that using react-ace. in my render function i have this row:
<CodeEditor onChange={onCodeChanged} value={code} />
callback function:
const onCodeBodyChanged = (newCode) => {
// some code ...
dispatch(setResource({ newCode }));
}
I want to test onCodeChanged
via RTL, so I tried to find the text area on change the value, but without any success
example of (not working) test:
const { container } = render(<ResourceEditorPanel />, createMockStore());
const ace = container.querySelectorAll('.ace_text-input');
fireEvent.change(ace, { target: { value: 'someText' } });
await waitFor(() => {
expect(dispatch).toHaveBeenCalled();
});
the problem is fireEvent.change(ace, { target: { value: 'someText' } });
doesn’t trigger my function - onCodeChanged.
Do you know how can I test it?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:10
Top Results From Across the Web
trigger react-ace onChange via React Testing Library (RTL)
[Solved]-trigger react-ace onChange via React Testing Library (RTL)-Reactjs. Search. score:-1. Ace editor awaits for an input event so you'll also need to ...
Read more >onChange event not firing · Issue #637 · testing-library ...
So I'm not sure the first option would be useful for this test, as (if I understand correctly), I would essentially be triggering...
Read more >How to Test onChange Events in React Testing Library
To select an option from an HTML select element, you will need to grab the element with either screen.getByTestId or screen.getByRole , and...
Read more >How do I trigger a change event on radio buttons in react- ...
import React from 'react'; import { render, cleanup, fireEvent } from 'react-testing-library'; import App from './App'; afterEach(cleanup); it(' ...
Read more >Testing events with react testing library
Lets see our first example, we will test onChange event for an input field. // app.js const [name, setName] = useState( ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@asso1985 No.
I was able to test it by using the
paste
event rather thanchange
. And here is what I do:Component:
Test: