Skip to content

Commit

Permalink
Update setValue.test.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 committed Jan 13, 2024
1 parent f759d33 commit 6aae0a3
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/__tests__/useForm/setValue.test.tsx
Expand Up @@ -1385,4 +1385,48 @@ describe('setValue', () => {
expect(screen.getByText('dirty')).toBeVisible();
expect(screen.getByText('touched')).toBeVisible();
});

it('should be able to set to empty array value', () => {
const App = () => {
const { register, setValue } = useForm({
values: {
item1: {
positions: [{ activities: ['Value1', 'Value2'] }],
},
item2: {
positions: [{ activities: ['Value1', 'Value2'] }],
},
},
});

return (
<form>
<input
{...register('item1.positions.0.activities')}
data-testid={'a'}
/>
<input
{...register('item2.positions.0.activities')}
data-testid={'b'}
/>

<button
type="button"
onClick={() => {
setValue('item1.positions', [{ activities: [] }]);
}}
>
Reset
</button>
</form>
);
};

render(<App />);

fireEvent.click(screen.getByRole('button'));

expect((screen.getByTestId('a') as HTMLInputElement).value).toEqual('');
expect((screen.getByTestId('b') as HTMLInputElement).value).toEqual('');
})

Check failure on line 1431 in src/__tests__/useForm/setValue.test.tsx

View workflow job for this annotation

GitHub Actions / build

Insert `;`
});

0 comments on commit 6aae0a3

Please sign in to comment.