Created
May 6, 2021 21:13
-
-
Save steve-codemunkies/ecf2464a59dad64567fd6a36c79bcb2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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