如何使用 react-testing-library 对屏蔽的输入字段进行单元测试。该组件是使用材料 ui 和 react-hook-form 开发的。在这里,您可以找到代码并在我身边处理示例。提前致谢
测试文件:
let Phone_Input = getByTestId("phone-input");
fireEvent.change(
<InputMask mask="(999) 999-9999">{() => Phone_Input}</InputMask>,
{
target: { value: "9500902621" }
}
);
零件:
<InputMask mask="(999) 999-9999">
{() => (
<TextField
id="standard-required"
name="phone"
label="phone"
placeholder="Enter Phone"
inputProps={{
"data-testid": "phone-input"
}}
/>
)}
</InputMask>
错误:
The given element does not have a value setter
expect(received).toBe(expected) // Object.is equality
Expected: "(950) 090-2621"
Received: "(___) ___-____"