Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import TextField from '@material-ui/core/TextField';
describe("TextField onChange demo", () => {
it.each`
initialValue | changeValue
${"test"} | ${"changed"}
${"test"} | ${"test"}
`("given a text field with initial value '$initialValue' when changed to '$changeValue' then the onChange handler should be called", ({ initialValue, changeValue }) => {
let onChangeCalled = null;
render(<TextField id="testing" label="Testing" value={ initialValue } onChange={ (e) => onChangeCalled = true } />);
fireEvent.change(screen.getByLabelText("Testing"), { target: { value: changeValue } });
expect(onChangeCalled).toBeTruthy();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment