From 9d52e11bbfddb18e2c0f086ddd4f9bd48ff570ec Mon Sep 17 00:00:00 2001 From: Beier Luo Date: Thu, 10 Jun 2021 21:27:26 +1000 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=A8=E2=80=8D=F0=9F=8F=AD=20include=20u?= =?UTF-8?q?nit=20test=20for=20setValue=20nested=20object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/useForm/setValue.test.tsx | 31 ++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/__tests__/useForm/setValue.test.tsx b/src/__tests__/useForm/setValue.test.tsx index 59f795326ce..031cecd8d15 100644 --- a/src/__tests__/useForm/setValue.test.tsx +++ b/src/__tests__/useForm/setValue.test.tsx @@ -1054,7 +1054,7 @@ describe('setValue', () => { }); }); - it('should only be able to update value of array of inputs which is not registered', async () => { + it('should only be able to update value of array which is not registered', async () => { const App = () => { const { setValue, watch } = useForm({ defaultValues: { @@ -1077,4 +1077,33 @@ describe('setValue', () => { screen.getByText('["2","2","3"]'); }); }); + + it('should only be able to update value of object which is not registered', async () => { + const App = () => { + const { setValue, watch } = useForm({ + defaultValues: { + test: { + data: '1', + data1: '2', + }, + }, + }); + + React.useEffect(() => { + setValue('test', { + data: '2', + } as any); + }, [setValue]); + + const result = watch('test'); + + return

{JSON.stringify(result)}

; + }; + + render(); + + await waitFor(async () => { + screen.getByText('{"data":"2","data1":"2"}'); + }); + }); });