In Jest, I am using fireEvent.click()
. I want to pass the parameter of the function that will be called after I click that button for click event.
expect(Searchmodal).toBeDefined();
render(<Searchmodal visible={true} />);
const button = screen.getByTestId("test-button");
const parameter = "123";
act(() => {
fireEvent.click(button, { target: { value: parameter } });
});
const { getByPlaceholderText } = render(<Searchmodal />);
const input = getByPlaceholderText("Search");
expect(input.value).toBe(parameter);
This code is failing to pass the parameter. How to pass the parameter in this fireEvent
? This is the JSX file component:
<button
id="datasource-link-apply-button"
data-testid="test-button"
type="secondary"
onClick={() => handleApplyClick("890")}
>
Apply
</button>
I tried:
{
target: {
value: parameter;
}
}
but it’s not working.
New contributor
user24934190 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.