You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've successfully implemented client and server side validation with Conform and my Remix app. However, I'm struggling to write meaningful test around with Jest and Testing Library. My problem appear to be somewhere around Conform not triggering validation onBlur or on Radio button select. I trued console logging the form.value and no matter what user interaction I simulate with userEvent I can't get the route component, containing the form to re-render. Could you please extend your Remix example with some simple tests, please?
My route component:
export default function AggregatorApplyHandover() {
const location = useLocation();
const { brand = '', product = '' } = useParams();
const { application, csrf, applicationId } = useLoaderData<typeof loader>();
const lastResult = useActionData<typeof action>();
const [form, fields] = useForm({
defaultValue: {
mobile: application?.mobile,
email: application?.email,
},
// Sync the result of last submission
lastResult,
// Reuse the validation logic on the client
onValidate({ formData }) {
return parseWithZod(formData, { schema: clientSchema });
},
// Validate the form on blur event triggered
shouldValidate: 'onBlur',
shouldRevalidate: 'onBlur',
});
const clientIsValid = clientSchema.safeParse(form.value).success;
console.log('>>', form.value);
return (
<AuthenticityTokenProvider token={csrf}>
...
<Form method="post" id={form.id} onSubmit={form.onSubmit} noValidate>
<AuthenticityTokenInput />
<IndependentInputField
id={genericFields.mobile}
type="digitOnly"
label="Mobile number"
maxLength={11}
tooltip={mobileTooltip}
key={fields.mobile.key}
name={fields.mobile.name}
defaultValue={fields.mobile.initialValue}
error={fields.mobile.errors?.toString()}
/>
<IndependentInputField
id={genericFields.email}
type="email"
label="Email"
maxLength={60}
minLength={7}
tooltip={emailTooltip}
key={fields.email.key}
name={fields.email.name}
defaultValue={fields.email.initialValue}
error={fields.email.errors?.toString()}
/>
<IndependentRadioButtonField
data-testid={genericFields.financialSituation}
id={genericFields.financialSituation}
label="Do you expect your financial situation to change in the near future which would impact your ability to make your repayments?"
isHeading
topText="Think about things like ill health, job loss or care for a dependant"
options={financialSituations()}
key={fields.financialSituation.key}
name={fields.financialSituation.name}
defaultValue={fields.financialSituation.initialValue ?? ''}
error={fields.financialSituation.errors?.toString()}
/>
<Button
data-testid="continue-submit-application"
id="submitApplication"
type="submit"
width="100%"
onClick={onClickSubmit}
isDisabled={!clientIsValid}
>
Continue my application
</Button>
</Form>
...
</AuthenticityTokenProvider>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I've successfully implemented client and server side validation with Conform and my Remix app. However, I'm struggling to write meaningful test around with Jest and Testing Library. My problem appear to be somewhere around Conform not triggering validation onBlur or on Radio button select. I trued console logging the
form.valueand no matter what user interaction I simulate withuserEventI can't get theroutecomponent, containing the form to re-render. Could you please extend your Remix example with some simple tests, please?My route component:
My test:
Beta Was this translation helpful? Give feedback.
All reactions