Skip to content

Commit

Permalink
add lacking expects to autoForm test
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnestTeluk committed Feb 24, 2023
1 parent 188b5e6 commit 81f69df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
25 changes: 8 additions & 17 deletions packages/uniforms/__tests__/AutoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('<AutoForm />', () => {
<AutoForm
// @ts-expect-error https://github.com/vazco/uniforms/issues/1165
name="form"
onChange={onChange}
schema={schema}
>
<AutoFields />
Expand Down Expand Up @@ -80,7 +81,6 @@ describe('<AutoForm />', () => {
expect(onChangeModel).toHaveBeenLastCalledWith({ a: '2' });
});
it('updates `changed` and `changedMap`', () => {
// FIXME: AutoForm is not a valid Component.
render(
<AutoForm schema={schema}>
<context.Consumer children={contextSpy} />
Expand Down Expand Up @@ -109,7 +109,6 @@ describe('<AutoForm />', () => {
}
}

// FIXME: AutoForm is not a valid Component.
render(
// @ts-expect-error Convoluted AutoForm types
<CustomAutoForm
Expand All @@ -132,18 +131,13 @@ describe('<AutoForm />', () => {
);

expect(onSubmit).not.toBeCalled();

await new Promise(resolve => setTimeout(resolve));

const input = screen.getByLabelText('A');

expect(onSubmit).toHaveBeenCalledTimes(1);
expect(onSubmit).toHaveBeenLastCalledWith({ a: '', b: '', c: '' });

await new Promise(resolve => setTimeout(resolve));
fireEvent.change(input, { target: { value: '1' } });

expect(validator).toHaveBeenCalledTimes(2);
await new Promise(resolve => setTimeout(resolve));
expect(onSubmit).toHaveBeenCalledTimes(1);
expect(onSubmit).toHaveBeenLastCalledWith({ a: '1', b: '', c: '' });
expect(validator).toHaveBeenCalledTimes(1);
expect(validator).toHaveBeenLastCalledWith({ a: '1', b: '', c: '' });
});
});
Expand Down Expand Up @@ -186,11 +180,7 @@ describe('<AutoForm />', () => {
<context.Consumer children={contextSpy} />
</AutoForm>
);
const { rerender } = render(
// FIXME: AutoForm is not a valid Component.
<Component />,
schemaDefinition,
);
const { rerender } = render(<Component />, schemaDefinition);

rerender(<Component />);

Expand All @@ -201,13 +191,14 @@ describe('<AutoForm />', () => {
});
describe('when update', () => {
it('<AutoForm />, updates', () => {
render(
const { rerenderWithProps } = render(
<AutoForm schema={schema}>
<context.Consumer children={contextSpy} />
</AutoForm>,
schemaDefinition,
);

rerenderWithProps({ model: {} });
expect(contextSpy).toHaveBeenLastCalledWith(
expect.objectContaining({ model: {} }),
);
Expand Down
4 changes: 3 additions & 1 deletion packages/uniforms/__tests__/useField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ describe('useField', () => {
const input = screen.getByRole('textbox');

expect(input).toHaveAttribute('value', '4');
fireEvent.change(input, { target: { value: null } });
expect(input).toHaveAttribute('value', '');
});

it('does not apply default value after first change', () => {
render(
<AutoForm label schema={bridge}>
<AutoForm schema={bridge}>
<TestComponent name="d" />
</AutoForm>,
);
Expand Down

0 comments on commit 81f69df

Please sign in to comment.