Skip to content

Commit

Permalink
馃И unit test for #5262 (#5269)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 committed May 20, 2021
1 parent d695d8f commit 16b1c40
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/__tests__/useForm/register.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,46 @@ describe('register', () => {
expect(watchedValue).toMatchSnapshot();
});

it.only('should skip register absent fields which are checkbox/radio inputs', async () => {
let data: unknown;

const App = () => {
const { register, handleSubmit } = useForm({
defaultValues: {
test: ['1', '2', '3'],
},
});
return (
<form onSubmit={handleSubmit((d) => (data = d))}>
<input type="checkbox" {...register('test')} value={'1'} />
<input type="checkbox" {...register('test')} value={'2'} />
<input type="checkbox" {...register('test')} value={'3'} />
<button>Submit</button>
</form>
);
};

render(<App />);

await act(async () => {
fireEvent.click(screen.getByRole('button'));
});

expect(data).toEqual({
test: ['1', '2', '3'],
});

fireEvent.click(screen.getAllByRole('checkbox')[0]);

await act(async () => {
fireEvent.click(screen.getByRole('button'));
});

expect(data).toEqual({
test: ['2', '3'],
});
});

describe('register valueAs', () => {
it('should return number value with valueAsNumber', async () => {
let output = {};
Expand Down

0 comments on commit 16b1c40

Please sign in to comment.