Skip to content

Commit e4eea54

Browse files
author
Said Shah
committed
Added test coverage for change handler
1 parent 4e27cc9 commit e4eea54

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/molecules/form-fields/input-form-field.test.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { render } from "@testing-library/react";
2+
import { render, fireEvent } from "@testing-library/react";
33
import {
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
});

0 commit comments

Comments
 (0)