这就是我如何让我的工作以多步形式工作,其中第 1 步里面有一个 cleave.js 组件。对表单库使用 react-hook-form
it('should test formatted input', async () => {
const { getByTestId } = render(<ProviderTestComponent><Step1 {...defaultProps} /></ProviderTestComponent>)
const arrayOfInputs = [
{
dataTestId: 'test',
testInput: '12345'
},
{
dataTestId: 'test.day',
testInput: '11'
},
{
dataTestId: 'test.month',
testInput: '11'
},
{
dataTestId: 'test.year',
testInput: '1950'
},
]
arrayOfInputs.forEach((item) => {
const inputField = getByTestId(item.dataTestId)
userEvent.type(inputField, item.testInput)
})
const nextButton = getByTestId('step1-next')
fireEvent.click(nextButton)
await waitFor(() => expect(handleOnSubmitMock).toHaveBeenCalled())
// ^ this needs to be awaited else the validation won't run for react-hook-form before cleave.js is finished
})