Problem here is TextField is an abstraction in MaterialUI. It consists of FormControl, Label and Input. Clean way of solving this problem is:
- First, add
InputPropson your TextField, withdata-testidattribute.
// YourComponent.js
<TextField
onChange={event => setContent(event.target.value)}
id="content"
inputProps={{ "data-testid": "content-input" }}
value={content}
label="Content"
/>
- Then simply query using this ID.
// YourComponent.test.js
const contentInput = getByTestId("content-input");
fireEvent.change(contentInput, {
target: { value: "new content" }
});
// and then assert stuff in here