-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added possibility to use browser builtin submit (#226)
* Added possibility to use browser builtin submit * Make sure preventDefaultSubmit works as expected * Revert unrelated change * Update Formsy-spec.tsx * Update API.md * Update Formsy-spec.tsx Co-authored-by: Kamil Burzynski <[email protected]> Co-authored-by: Robert Kuykendall <[email protected]>
- Loading branch information
1 parent
b8881d0
commit 761b3ef
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -457,6 +457,41 @@ describe('Update a form', () => { | |
expect(input.instance().getErrorMessage()).toEqual(null); | ||
}); | ||
|
||
it('should prevent a default submit', () => { | ||
class TestForm extends React.Component { | ||
render() { | ||
return ( | ||
<Formsy> | ||
<TestInput name="foo" validations="isEmail" value="[email protected]" /> | ||
</Formsy> | ||
); | ||
} | ||
} | ||
const form = mount(<TestForm />); | ||
const FoundForm = form.find(TestForm); | ||
const submitEvent = {preventDefault: jest.fn()}; | ||
FoundForm.simulate('submit', submitEvent); | ||
expect(submitEvent.preventDefault).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should not prevent a default submit when preventDefaultSubmit is passed', () => { | ||
class TestForm extends React.Component { | ||
render() { | ||
return ( | ||
<Formsy preventDefaultSubmit={false}> | ||
<TestInput name="foo" validations="isEmail" value="[email protected]" /> | ||
</Formsy> | ||
); | ||
} | ||
} | ||
const form = mount(<TestForm />); | ||
const FoundForm = form.find(TestForm); | ||
const submitEvent = {preventDefault: jest.fn()}; | ||
FoundForm.simulate('submit', submitEvent); | ||
expect(submitEvent.preventDefault).not.toHaveBeenCalled(); | ||
}); | ||
|
||
|
||
it('should trigger an onValidSubmit when submitting a valid form', () => { | ||
const isCalled = jest.fn(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters