Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { render, waitFor } from '@testing-library/react'
3import { formOptions } from '@tanstack/form-core'
4import userEvent from '@testing-library/user-event'
5import { createFormHook, createFormHookContexts, useStore } from '../src'
6β
7const user = userEvent.setup()
8β
9const { fieldContext, useFieldContext, formContext, useFormContext } =
10 createFormHookContexts()
11β
12function TextField({ label }: { label: string }) {
13 const field = useFieldContext<string>()
14 return (
15 <label>
16 <div>{label}</div>
17 <input
18 value={field.state.value}
19 onChange={(e) => field.handleChange(e.target.value)}
20 />
21 </label>
22 )
23}
24β
25function SubscribeButton({ label }: { label: string }) {
26 const form = useFormContext()
27 return (
28 <form.Subscribe selector={(state) => state.isSubmitting}>
29 {(isSubmitting) => <button disabled={isSubmitting}>{label}</button>}
30 </form.Subscribe>
31 )
32}
33β
34const { useAppForm, withForm, withFieldGroup, useTypedAppFormContext } =
35 createFormHook({
36 fieldComponents: {
37 TextField,
38 },
39 formComponents: {
40 SubscribeButton,
41 },
42 fieldContext,
43 formContext,
44 })
45β
46describe('createFormHook', () => {
47 it('should allow to set default value', () => {
48 type Person = {
49 firstName: string
50 lastName: string
51 }
52β
53 function Comp() {
54 const form = useAppForm({
55 defaultValues: {
56 firstName: 'FirstName',
57 lastName: 'LastName',
58 } as Person,
59 })
60β
61 return (
62 <>
63 <form.AppField
64 name="firstName"
65 children={(field) => <field.TextField label="Testing" />}
66 />
67 </>
68 )
69 }
70β
71 const { getByLabelText } = render(<Comp />)
72 const input = getByLabelText('Testing')
73 expect(input).toHaveValue('FirstName')
74 })
75β
76 it('should handle withForm types properly', () => {
77 const formOpts = formOptions({
78 defaultValues: {
79 firstName: 'John',
80 lastName: 'Doe',
81 },
82 })
83β
84 const ChildForm = withForm({
85 ...formOpts,
86 // Optional, but adds props to the `render` function outside of `form`
87 props: {
88 title: 'Child Form',
89 },
90 render: ({ form, title }) => {
91 return (
92 <div>
93 <p>{title}</p>
94 <form.AppField
95 name="firstName"
96 children={(field) => <field.TextField label="First Name" />}
97 />
98 <form.AppForm>
99 <form.SubscribeButton label="Submit" />
100 </form.AppForm>
101 </div>
102 )
103 },
104 })
105β
106 const Parent = () => {
107 const form = useAppForm({
108 ...formOpts,
109 })
110β
111 return <ChildForm form={form} title={'Testing'} />
112 }
113β
114 const { getByLabelText, getByText } = render(<Parent />)
115 const input = getByLabelText('First Name')
116 expect(input).toHaveValue('John')
117 expect(getByText('Testing')).toBeInTheDocument()
118 })
119β
120 it('should handle withFieldGroup types properly', () => {
121 const formOpts = formOptions({
122 defaultValues: {
123 person: {
124 firstName: 'John',
125 lastName: 'Doe',
126 },
127 },
128 })
129β
130 const ChildForm = withFieldGroup({
131 defaultValues: formOpts.defaultValues.person,
132 // Optional, but adds props to the `render` function outside of `form`
133 props: {
134 title: 'Child Form',
135 },
136 render: ({ group, title }) => {
137 return (
138 <div>
139 <p>{title}</p>
140 <group.AppField
141 name="firstName"
142 children={(field) => <field.TextField label="First Name" />}
143 />
144 <group.AppForm>
145 <group.SubscribeButton label="Submit" />
146 </group.AppForm>
147 </div>
148 )
149 },
150 })
151β
152 const Parent = () => {
153 const form = useAppForm({
154 ...formOpts,
155 })
156β
157 return <ChildForm form={form} fields="person" title={'Testing'} />
158 }
159β
160 const { getByLabelText, getByText } = render(<Parent />)
161 const input = getByLabelText('First Name')
162 expect(input).toHaveValue('John')
163 expect(getByText('Testing')).toBeInTheDocument()
164 })
165β
166 it('should use the correct field name in Field with withFieldGroup', () => {
167 const formOpts = formOptions({
168 defaultValues: {
169 person: {
170 firstName: 'John',
171 lastName: 'Doe',
172 },
173 people: [
174 {
175 firstName: 'Jane',
176 lastName: 'Doe',
177 },
178 {
179 firstName: 'Robert',
180 lastName: 'Doe',
181 },
182 ],
183 },
184 })
185β
186 const ChildFormAsField = withFieldGroup({
187 defaultValues: formOpts.defaultValues.person,
188 render: ({ group }) => {
189 return (
190 <div>
191 <group.AppField
192 name="firstName"
193 children={(field) => <field.TextField label={field.name} />}
194 />
195 <group.AppForm>
196 <group.SubscribeButton label="Submit" />
197 </group.AppForm>
198 </div>
199 )
200 },
201 })
202 const ChildFormAsArray = withFieldGroup({
203 defaultValues: [formOpts.defaultValues.person],
204 props: {
205 title: '',
206 },
207 render: ({ group, title }) => {
208 return (
209 <div>
210 <p>{title}</p>
211 <group.AppField
212 name="[0].firstName"
213 children={(field) => <field.TextField label={field.name} />}
214 />
215 <group.AppForm>
216 <group.SubscribeButton label="Submit" />
217 </group.AppForm>
218 </div>
219 )
220 },
221 })
222β
223 const Parent = () => {
224 const form = useAppForm({
225 ...formOpts,
226 })
227β
228 return (
229 <>
230 <ChildFormAsField form={form} fields="person" />
231 <ChildFormAsArray form={form} fields="people" title="Testing" />
232 <ChildFormAsField form={form} fields="people[1]" />
233 </>
234 )
235 }
236β
237 const { getByLabelText, getByText } = render(<Parent />)
238 const inputField1 = getByLabelText('person.firstName')
239 const inputArray = getByLabelText('people[0].firstName')
240 const inputField2 = getByLabelText('people[1].firstName')
241 expect(inputField1).toHaveValue('John')
242 expect(inputArray).toHaveValue('Jane')
243 expect(inputField2).toHaveValue('Robert')
244 expect(getByText('Testing')).toBeInTheDocument()
245 })
246β
247 it('should forward Field and Subscribe to the form', () => {
248 const formOpts = formOptions({
249 defaultValues: {
250 person: {
251 firstName: 'John',
252 lastName: 'Doe',
253 },
254 },
255 })
256β
257 const ChildFormAsField = withFieldGroup({
258 defaultValues: formOpts.defaultValues.person,
259 render: ({ group }) => {
260 return (
261 <div>
262 <group.Field
263 name="firstName"
264 children={(field) => (
265 <label>
266 <div>{field.name}</div>
267 <input
268 value={field.state.value}
269 onChange={(e) => field.handleChange(e.target.value)}
270 />
271 </label>
272 )}
273 />
274 <group.Subscribe selector={(state) => state.values.lastName}>
275 {(lastName) => <p>{lastName}</p>}
276 </group.Subscribe>
277 </div>
278 )
279 },
280 })
281β
282 const Parent = () => {
283 const form = useAppForm({
284 ...formOpts,
285 })
286 return <ChildFormAsField form={form} fields="person" />
287 }
288β
289 const { getByLabelText, getByText } = render(<Parent />)
290 const input = getByLabelText('person.firstName')
291 expect(input).toHaveValue('John')
292 expect(getByText('Doe')).toBeInTheDocument()
293 })
294β
295 it('should not lose focus on update with withFieldGroup', async () => {
296 const formOpts = formOptions({
297 defaultValues: {
298 person: {
299 firstName: 'John',
300 lastName: 'Doe',
301 },
302 },
303 })
304β
305 const ChildForm = withFieldGroup({
306 defaultValues: formOpts.defaultValues.person,
307 render: function Render({ group }) {
308 const firstName = useStore(
309 group.store,
310 (state) => state.values.firstName,
311 )
312 return (
313 <div>
314 <p>{firstName}</p>
315 <group.Field
316 name="firstName"
317 children={(field) => (
318 <label>
319 <div>{field.name}</div>
320 <input
321 value={field.state.value}
322 onChange={(e) => field.handleChange(e.target.value)}
323 />
324 </label>
325 )}
326 />
327 <group.Subscribe selector={(state) => state.values.lastName}>
328 {(lastName) => <p>{lastName}</p>}
329 </group.Subscribe>
330 </div>
331 )
332 },
333 })
334β
335 const Parent = () => {
336 const form = useAppForm({
337 ...formOpts,
338 })
339 return <ChildForm form={form} fields="person" />
340 }
341β
342 const { getByLabelText } = render(<Parent />)
343β
344 const input = getByLabelText('person.firstName')
345 input.focus()
346 expect(input).toHaveFocus()
347β
348 await user.clear(input)
349 await user.type(input, 'Something')
350β
351 expect(input).toHaveFocus()
352 })
353β
354 it('should allow nesting withFieldGroup in other withFieldGroups', () => {
355 type Nested = {
356 firstName: string
357 }
358 type Wrapper = {
359 field: Nested
360 }
361 type FormValues = {
362 form: Wrapper
363 unrelated: { something: { lastName: string } }
364 }
365β
366 const defaultValues: FormValues = {
367 form: {
368 field: {
369 firstName: 'Test',
370 },
371 },
372 unrelated: {
373 something: {
374 lastName: '',
375 },
376 },
377 }
378β
379 const LensNested = withFieldGroup({
380 defaultValues: defaultValues.form.field,
381 render: function Render({ group }) {
382 return (
383 <group.Field name="firstName">
384 {(field) => <p>{field.name}</p>}
385 </group.Field>
386 )
387 },
388 })
389 const LensWrapper = withFieldGroup({
390 defaultValues: defaultValues.form,
391 render: function Render({ group }) {
392 return (
393 <div>
394 <LensNested form={group} fields="field" />
395 </div>
396 )
397 },
398 })
399β
400 const Parent = () => {
401 const form = useAppForm({
402 defaultValues,
403 })
404 return <LensWrapper form={form} fields="form" />
405 }
406β
407 const { getByText } = render(<Parent />)
408β
409 expect(getByText('form.field.firstName')).toBeInTheDocument()
410 })
411β
412 it('should allow mapping withFieldGroup to different values', () => {
413 const formOpts = formOptions({
414 defaultValues: {
415 unrelated: 'John',
416 values: '',
417 },
418 })
419β
420 const ChildFormAsField = withFieldGroup({
421 defaultValues: { firstName: '', lastName: '' },
422 render: ({ group }) => {
423 return (
424 <div>
425 <group.AppField
426 name="firstName"
427 children={(field) => <field.TextField label={field.name} />}
428 />
429 </div>
430 )
431 },
432 })
433β
434 const Parent = () => {
435 const form = useAppForm({
436 ...formOpts,
437 })
438β
439 return (
440 <ChildFormAsField
441 form={form}
442 fields={{
443 firstName: 'unrelated',
444 lastName: 'values',
445 }}
446 />
447 )
448 }
449β
450 const { getByLabelText } = render(<Parent />)
451 const inputField1 = getByLabelText('unrelated')
452 expect(inputField1).toHaveValue('John')
453 })
454β
455 it('should remap FieldGroupApi.Field validators to the correct names', () => {
456 const FieldGroupString = withFieldGroup({
457 defaultValues: { password: '', confirmPassword: '' },
458 render: function Render({ group }) {
459 return (
460 <group.Field
461 name="password"
462 validators={{
463 onChange: () => null,
464 onChangeListenTo: ['password'],
465 onBlur: () => null,
466 onBlurListenTo: ['confirmPassword'],
467 }}
468 >
469 {(field) => {
470 expect(field.options.validators?.onChangeListenTo).toStrictEqual([
471 'account.password',
472 ])
473 expect(field.options.validators?.onBlurListenTo).toStrictEqual([
474 'account.confirmPassword',
475 ])
476 return <></>
477 }}
478 </group.Field>
479 )
480 },
481 })
482β
483 const FieldGroupObject = withFieldGroup({
484 defaultValues: { password: '', confirmPassword: '' },
485 render: function Render({ group }) {
486 return (
487 <group.Field
488 name="password"
489 validators={{
490 onChange: () => null,
491 onChangeListenTo: ['password'],
492 onBlur: () => null,
493 onBlurListenTo: ['confirmPassword'],
494 }}
495 >
496 {(field) => {
497 expect(field.options.validators?.onChangeListenTo).toStrictEqual([
498 'userPassword',
499 ])
500 expect(field.options.validators?.onBlurListenTo).toStrictEqual([
501 'userConfirmPassword',
502 ])
503 return <></>
504 }}
505 </group.Field>
506 )
507 },
508 })
509β
510 const Parent = () => {
511 const form = useAppForm({
512 defaultValues: {
513 account: {
514 password: '',
515 confirmPassword: '',
516 },
517 userPassword: '',
518 userConfirmPassword: '',
519 },
520 })
521β
522 return (
523 <>
524 <FieldGroupString form={form} fields="account" />
525 <FieldGroupObject
526 form={form}
527 fields={{
528 password: 'userPassword',
529 confirmPassword: 'userConfirmPassword',
530 }}
531 />
532 </>
533 )
534 }
535β
536 render(<Parent />)
537 })
538β
539 it('should accept formId and return it', async () => {
540 function Submit() {
541 const form = useFormContext()
542β
543 return (
544 <button type="submit" form={form.formId} data-testid="formId-target">
545 {form.formId}
546 </button>
547 )
548 }
549β
550 function Comp() {
551 const form = useAppForm({
552 formId: 'test',
553 })
554β
555 return (
556 <form.AppForm>
557 <form
558 id={form.formId}
559 onSubmit={(e) => {
560 e.preventDefault()
561 form.handleSubmit()
562 }}
563 ></form>
564β
565 <form.Subscribe
566 selector={(state) => state.submissionAttempts}
567 children={(submissionAttempts) => (
568 <span data-testid="formId-result">{submissionAttempts}</span>
569 )}
570 />
571β
572 <Submit />
573 </form.AppForm>
574 )
575 }
576β
577 const { getByTestId } = render(<Comp />)
578 const target = getByTestId('formId-target')
579 const result = getByTestId('formId-result')
580β
581 await user.click(target)
582 expect(result).toHaveTextContent('1')
583 })
584β
585 it('should allow using typed app form', () => {
586 type Person = {
587 firstName: string
588 lastName: string
589 }
590 const formOpts = formOptions({
591 defaultValues: {
592 firstName: 'FirstName',
593 lastName: 'LastName',
594 } as Person,
595 })
596β
597 function Child() {
598 const form = useTypedAppFormContext(formOpts)
599β
600 return (
601 <form.AppField
602 name="firstName"
603 children={(field) => <field.TextField label="Testing" />}
604 />
605 )
606 }
607β
608 function Parent() {
609 const form = useAppForm({
610 defaultValues: {
611 firstName: 'FirstName',
612 lastName: 'LastName',
613 } as Person,
614 })
615β
616 return (
617 <form.AppForm>
618 <Child />
619 </form.AppForm>
620 )
621 }
622β
623 const { getByLabelText } = render(<Parent />)
624 const input = getByLabelText('Testing')
625 expect(input).toHaveValue('FirstName')
626 })
627β
628 it('should throw if `useTypedAppFormContext` is used without AppForm', () => {
629 type Person = {
630 firstName: string
631 lastName: string
632 }
633 const formOpts = formOptions({
634 defaultValues: {
635 firstName: 'FirstName',
636 lastName: 'LastName',
637 } as Person,
638 })
639β
640 function Child() {
641 const form = useTypedAppFormContext(formOpts)
642β
643 return (
644 <form.AppField
645 name="firstName"
646 children={(field) => <field.TextField label="Testing" />}
647 />
648 )
649 }
650β
651 function Parent() {
652 const form = useAppForm({
653 defaultValues: {
654 firstName: 'FirstName',
655 lastName: 'LastName',
656 } as Person,
657 })
658β
659 return <Child />
660 }
661β
662 expect(() => render(<Parent />)).toThrow()
663 })
664β
665 it('should allow using typed app form with form components', () => {
666 type Person = {
667 firstName: string
668 lastName: string
669 }
670 const formOpts = formOptions({
671 defaultValues: {
672 firstName: 'FirstName',
673 lastName: 'LastName',
674 } as Person,
675 })
676β
677 function Child() {
678 const form = useTypedAppFormContext(formOpts)
679β
680 return <form.SubscribeButton label="Testing" />
681 }
682β
683 function Parent() {
684 const form = useAppForm({
685 defaultValues: {
686 firstName: 'FirstName',
687 lastName: 'LastName',
688 } as Person,
689 })
690β
691 return (
692 <form.AppForm>
693 <Child />
694 </form.AppForm>
695 )
696 }
697β
698 const { getByText } = render(<Parent />)
699 const button = getByText('Testing')
700 expect(button).toBeInTheDocument()
701 })
702β
703 describe('extendForm', () => {
704 it('should include both parent and extended field components', () => {
705 function ExtendedTextField({ label }: { label: string }) {
706 const field = useFieldContext<string>()
707 return (
708 <label>
709 <div>{label}</div>
710 <input
711 data-testid="extended-input"
712 value={field.state.value}
713 onChange={(e) => field.handleChange(e.target.value)}
714 />
715 </label>
716 )
717 }
718β
719 const { useAppForm: useExtendedForm } = createFormHook({
720 fieldComponents: { TextField },
721 formComponents: { SubscribeButton },
722 fieldContext,
723 formContext,
724 }).extendForm({
725 fieldComponents: { ExtendedTextField },
726 })
727β
728 function Comp() {
729 const form = useExtendedForm({
730 defaultValues: { firstName: 'John', lastName: 'Doe' },
731 })
732β
733 return (
734 <>
735 <form.AppField
736 name="firstName"
737 children={(field) => <field.TextField label="First Name" />}
738 />
739 <form.AppField
740 name="lastName"
741 children={(field) => (
742 <field.ExtendedTextField label="Last Name" />
743 )}
744 />
745 </>
746 )
747 }
748β
749 const { getByLabelText, getByTestId } = render(<Comp />)
750 expect(getByLabelText('First Name')).toHaveValue('John')
751 expect(getByTestId('extended-input')).toHaveValue('Doe')
752 })
753β
754 it('should include both parent and extended form components', () => {
755 function ExtendedSubmit({ label }: { label: string }) {
756 const form = useFormContext()
757 return (
758 <form.Subscribe selector={(state) => state.isSubmitting}>
759 {(isSubmitting) => (
760 <button
761 data-testid="extended-submit"
762 disabled={isSubmitting}
763 type="button"
764 >
765 {label}
766 </button>
767 )}
768 </form.Subscribe>
769 )
770 }
771β
772 const { useAppForm: useExtendedForm } = createFormHook({
773 fieldComponents: { TextField },
774 formComponents: { SubscribeButton },
775 fieldContext,
776 formContext,
777 }).extendForm({
778 formComponents: { ExtendedSubmit },
779 })
780β
781 function Comp() {
782 const form = useExtendedForm({
783 defaultValues: { firstName: 'John' },
784 })
785β
786 return (
787 <form.AppForm>
788 <form.SubscribeButton label="Submit" />
789 <form.ExtendedSubmit label="Extended Submit" />
790 </form.AppForm>
791 )
792 }
793β
794 const { getByText, getByTestId } = render(<Comp />)
795 expect(getByText('Submit')).toBeInTheDocument()
796 expect(getByTestId('extended-submit')).toHaveTextContent(
797 'Extended Submit',
798 )
799 })
800β
801 it('should support chaining multiple extendForm calls', () => {
802 function FieldA({ label }: { label: string }) {
803 const field = useFieldContext<string>()
804 return (
805 <label>
806 <div>{label}</div>
807 <input
808 value={field.state.value}
809 onChange={(e) => field.handleChange(e.target.value)}
810 />
811 </label>
812 )
813 }
814β
815 function FieldB({ label }: { label: string }) {
816 const field = useFieldContext<string>()
817 return (
818 <label>
819 <div>{label}</div>
820 <input
821 value={field.state.value}
822 onChange={(e) => field.handleChange(e.target.value)}
823 />
824 </label>
825 )
826 }
827β
828 const base = createFormHook({
829 fieldComponents: { TextField },
830 formComponents: {},
831 fieldContext,
832 formContext,
833 })
834β
835 const { useAppForm: useChainedForm } = base
836 .extendForm({ fieldComponents: { FieldA } })
837 .extendForm({ fieldComponents: { FieldB } })
838β
839 function Comp() {
840 const form = useChainedForm({
841 defaultValues: { a: 'valueA', b: 'valueB', c: 'valueC' },
842 })
843β
844 return (
845 <>
846 <form.AppField
847 name="a"
848 children={(field) => <field.TextField label="A" />}
849 />
850 <form.AppField
851 name="b"
852 children={(field) => <field.FieldA label="B" />}
853 />
854 <form.AppField
855 name="c"
856 children={(field) => <field.FieldB label="C" />}
857 />
858 </>
859 )
860 }
861β
862 const { getByLabelText } = render(<Comp />)
863 expect(getByLabelText('A')).toHaveValue('valueA')
864 expect(getByLabelText('B')).toHaveValue('valueB')
865 expect(getByLabelText('C')).toHaveValue('valueC')
866 })
867β
868 it('should work with withForm after extendForm', () => {
869 function ExtendedTextField({ label }: { label: string }) {
870 const field = useFieldContext<string>()
871 return (
872 <label>
873 <div>{label}</div>
874 <input
875 value={field.state.value}
876 onChange={(e) => field.handleChange(e.target.value)}
877 />
878 </label>
879 )
880 }
881β
882 const { useAppForm: useExtendedForm, withForm: withExtendedForm } =
883 createFormHook({
884 fieldComponents: { TextField },
885 formComponents: { SubscribeButton },
886 fieldContext,
887 formContext,
888 }).extendForm({
889 fieldComponents: { ExtendedTextField },
890 })
891β
892 const ChildForm = withExtendedForm({
893 defaultValues: { firstName: 'Jane', lastName: 'Smith' },
894 render: function Render({ form }) {
895 return (
896 <>
897 <form.AppField
898 name="firstName"
899 children={(field) => <field.TextField label="First Name" />}
900 />
901 <form.AppField
902 name="lastName"
903 children={(field) => (
904 <field.ExtendedTextField label="Last Name" />
905 )}
906 />
907 </>
908 )
909 },
910 })
911β
912 function Parent() {
913 const form = useExtendedForm({
914 defaultValues: { firstName: 'Jane', lastName: 'Smith' },
915 })
916 return <ChildForm form={form} />
917 }
918β
919 const { getByLabelText } = render(<Parent />)
920 expect(getByLabelText('First Name')).toHaveValue('Jane')
921 expect(getByLabelText('Last Name')).toHaveValue('Smith')
922 })
923β
924 it('should return a new extendForm from the extended hook', () => {
925 function ExtendedTextField({ label }: { label: string }) {
926 const field = useFieldContext<string>()
927 return (
928 <label>
929 <div>{label}</div>
930 <input
931 value={field.state.value}
932 onChange={(e) => field.handleChange(e.target.value)}
933 />
934 </label>
935 )
936 }
937β
938 const base = createFormHook({
939 fieldComponents: { TextField },
940 formComponents: { SubscribeButton },
941 fieldContext,
942 formContext,
943 })
944β
945 const extended = base.extendForm({
946 fieldComponents: { ExtendedTextField },
947 })
948β
949 // extendForm should itself expose extendForm
950 expect(typeof extended.extendForm).toBe('function')
951 })
952 })
953β
954 it('should render FieldGroup Subscribe without selector (default identity)', async () => {
955 const formOpts = formOptions({
956 defaultValues: {
957 person: {
958 firstName: 'FirstName',
959 lastName: 'LastName',
960 },
961 },
962 })
963β
964 const ChildFormAsField = withFieldGroup({
965 defaultValues: formOpts.defaultValues.person,
966 render: ({ group }) => {
967 return (
968 <div>
969 <group.Field
970 name="lastName"
971 children={(field) => (
972 <label>
973 Last Name:
974 <input
975 data-testid="lastName"
976 value={field.state.value}
977 onBlur={field.handleBlur}
978 onChange={(e) => field.handleChange(e.target.value)}
979 />
980 </label>
981 )}
982 />
983 <group.Subscribe
984 children={(state) => (
985 <span data-testid="state-lastName">
986 {state.values.lastName}
987 </span>
988 )}
989 />
990 </div>
991 )
992 },
993 })
994β
995 const Parent = () => {
996 const form = useAppForm({
997 ...formOpts,
998 })
999 return <ChildFormAsField form={form} fields="person" />
1000 }
1001β
1002 const { getByTestId } = render(<Parent />)
1003 const input = getByTestId('lastName')
1004 const stateLastName = getByTestId('state-lastName')
1005β
1006 expect(stateLastName).toHaveTextContent('LastName')
1007β
1008 await user.clear(input)
1009 await user.type(input, 'Updated')
1010 await waitFor(() => expect(stateLastName).toHaveTextContent('Updated'))
1011 })
1012})