Skip to content

Commit

Permalink
πŸ‘¨β€πŸ­ include unit test for setValue nested object
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 committed Jun 10, 2021
1 parent ae8db23 commit 9d52e11
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/__tests__/useForm/setValue.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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 <p>{JSON.stringify(result)}</p>;
};

render(<App />);

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

0 comments on commit 9d52e11

Please sign in to comment.