File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
src/molecules/form-fields Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 11import React from "react" ;
2- import { render } from "@testing-library/react" ;
2+ import { render , fireEvent } from "@testing-library/react" ;
33import {
44 InputFormField ,
55 InvalidInputFormValueClass ,
@@ -137,4 +137,28 @@ describe("InputFormField", () => {
137137 ShowLabelForScreenReadersOnlyClass
138138 ) ;
139139 } ) ;
140+
141+ test ( "when onChange set, calls handler upon change" , ( ) => {
142+ // Arrange
143+ let isChecked = false ;
144+ const expected = faker . random . word ( ) ;
145+ const handleChange = ( ) => ( isChecked = true ) ;
146+ const inputTestId = "inputTestId" ;
147+
148+ // Act
149+ const { getByTestId } = render (
150+ < InputFormField
151+ label = { expected }
152+ onChange = { handleChange }
153+ inputTestId = { inputTestId }
154+ />
155+ ) ;
156+
157+ fireEvent . change ( getByTestId ( inputTestId ) , {
158+ target : { value : faker . random . word ( ) } ,
159+ } ) ;
160+
161+ // Assert
162+ expect ( isChecked ) . toBeTrue ( ) ;
163+ } ) ;
140164} ) ;
You can’t perform that action at this time.
0 commit comments