Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update form onSubmit to be a function #8

Merged
merged 1 commit into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hooks/use-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export default function useForm(options: Options) {
return;
}

onSubmit(state.values, { reset }).then(
Promise.resolve(onSubmit(state.values, { reset })).then(
() => {
dispatch({
payload: {},
Expand Down
42 changes: 21 additions & 21 deletions test/src/hooks/use-form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('useForm hook', () => {
const { result } = renderHook(() => useForm({
initialValues: { foo: 'bar' },
jsonSchema: { type: 'object' },
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

expect(result.current.state.values).toEqual({
Expand All @@ -27,7 +27,7 @@ describe('useForm hook', () => {
const onValuesChanged = jest.fn();
const { result } = renderHook(() => useForm({
jsonSchema: { type: 'object' },
onSubmit: () => Promise.resolve(),
onSubmit: () => {},
onValuesChanged
}));

Expand All @@ -42,7 +42,7 @@ describe('useForm hook', () => {
it('should set the field to inactive and touched', () => {
const { result } = renderHook(() => useForm({
jsonSchema: { type: 'object' },
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

act(() => {
Expand All @@ -64,7 +64,7 @@ describe('useForm hook', () => {
},
type: 'object'
},
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

act(() => {
Expand All @@ -79,7 +79,7 @@ describe('useForm hook', () => {
it('should set the field to active and touched', () => {
const { result } = renderHook(() => useForm({
jsonSchema: { type: 'object' },
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

act(() => {
Expand All @@ -101,7 +101,7 @@ describe('useForm hook', () => {
},
type: 'object'
},
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

act(() => {
Expand All @@ -116,7 +116,7 @@ describe('useForm hook', () => {
it('should register the field', () => {
const { result } = renderHook(() => useForm({
jsonSchema: { type: 'object' },
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

expect(result.current.state.values).not.toHaveProperty('foo');
Expand All @@ -134,7 +134,7 @@ describe('useForm hook', () => {
const { result } = renderHook(() => useForm({
initialValues: { foo: 'bar' },
jsonSchema: { type: 'object' },
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

act(() => {
Expand All @@ -153,7 +153,7 @@ describe('useForm hook', () => {
},
type: 'object'
},
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

act(() => {
Expand All @@ -168,7 +168,7 @@ describe('useForm hook', () => {
it('should clear the form values', () => {
const { result } = renderHook(() => useForm({
jsonSchema: { type: 'object' },
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

act(() => {
Expand All @@ -183,7 +183,7 @@ describe('useForm hook', () => {
const { result } = renderHook(() => useForm({
initialValues: { foo: 'bar' },
jsonSchema: { type: 'object' },
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

act(() => {
Expand All @@ -202,7 +202,7 @@ describe('useForm hook', () => {
},
type: 'object'
},
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

act(() => {
Expand All @@ -216,7 +216,7 @@ describe('useForm hook', () => {
it('should set all fields to inactive and untouched', () => {
const { result } = renderHook(() => useForm({
jsonSchema: { type: 'object' },
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

act(() => {
Expand All @@ -238,7 +238,7 @@ describe('useForm hook', () => {
it('should set the field value', () => {
const { result } = renderHook(() => useForm({
jsonSchema: { type: 'object' },
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

act(() => {
Expand All @@ -256,7 +256,7 @@ describe('useForm hook', () => {
},
type: 'object'
},
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

act(() => {
Expand All @@ -269,7 +269,7 @@ describe('useForm hook', () => {

describe('submit', () => {
it('should call the `onSubmit` option with the form values and actions', async () => {
const onSubmit = jest.fn(() => Promise.resolve());
const onSubmit = jest.fn();
const { result, waitForNextUpdate } = renderHook(() => useForm({
initialValues: { foo: 'bar' },
jsonSchema: { type: 'object' },
Expand All @@ -289,7 +289,7 @@ describe('useForm hook', () => {
});

it('should not call `onSubmit` when the form has errors', () => {
const onSubmit = jest.fn(() => Promise.resolve());
const onSubmit = jest.fn();
const { rerender, result } = renderHook(() => useForm({
initialValues: { foo: 1 },
jsonSchema: {
Expand All @@ -315,7 +315,7 @@ describe('useForm hook', () => {
it('should set the `isSubmitting` flag', async () => {
expect.assertions(2);

const onSubmit = jest.fn(() => Promise.resolve());
const onSubmit = jest.fn();
const { result, waitForNextUpdate } = renderHook(() => useForm({
jsonSchema: { type: 'object' },
onSubmit
Expand All @@ -333,7 +333,7 @@ describe('useForm hook', () => {
});

it('should not reset the form values', async () => {
const onSubmit = jest.fn(() => Promise.resolve());
const onSubmit = jest.fn();
const { result, waitForNextUpdate } = renderHook(() => useForm({
jsonSchema: { type: 'object' },
onSubmit
Expand All @@ -352,7 +352,7 @@ describe('useForm hook', () => {
it('should set all fields to touched', async () => {
const { result, waitForNextUpdate } = renderHook(() => useForm({
jsonSchema: { type: 'object' },
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

act(() => {
Expand All @@ -378,7 +378,7 @@ describe('useForm hook', () => {
},
type: 'object'
},
onSubmit: () => Promise.resolve()
onSubmit: () => {}
}));

act(() => {
Expand Down