How to unit test the masked input field using react-testing-library. That component has developed using material ui and react-hook-form. Here you can find the code and worked on examples from my side. Thanks in advance
Test file:
let Phone_Input = getByTestId("phone-input");
fireEvent.change(
<InputMask mask="(999) 999-9999">{() => Phone_Input}</InputMask>,
{
target: { value: "9500902621" }
}
);
Component:
<InputMask mask="(999) 999-9999">
{() => (
<TextField
id="standard-required"
name="phone"
label="phone"
placeholder="Enter Phone"
inputProps={{
"data-testid": "phone-input"
}}
/>
)}
</InputMask>
Error:
The given element does not have a value setter
expect(received).toBe(expected) // Object.is equality
Expected: "(950) 090-2621"
Received: "(___) ___-____"