Skip to content

Instantly share code, notes, and snippets.

@steve-codemunkies
Created May 6, 2021 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steve-codemunkies/ecf2464a59dad64567fd6a36c79bcb2b to your computer and use it in GitHub Desktop.
Save steve-codemunkies/ecf2464a59dad64567fd6a36c79bcb2b to your computer and use it in GitHub Desktop.
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