-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
add validationSchema to FormikContext #2090
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as React from 'react'; | ||
import { render } from 'react-testing-library'; | ||
import { Formik } from '../src/Formik'; | ||
import { useFormikContext } from '../src/FormikContext'; | ||
|
||
describe('FormikContext', () => { | ||
describe('useFormikContext', () => { | ||
it('should return validationContext if set', () => { | ||
const validationSchema = 'validationSchema'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is |
||
|
||
const AComponenent: React.FC = () => { | ||
const formikContext = useFormikContext(); | ||
expect(formikContext.validationSchema).toBe(validationSchema); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it proper to put tests inside of components? I've never tried it. The normal formik renderer in the rest of the tests exposes the props to the test runner via a special API, like this: const validate = jest.fn(() => Promise.resolve({}));
const validationSchema = {
validate,
};
const { getProps } = renderFormik({
validationSchema,
});
expect(getProps().validationSchema).toBe(validationSchema); I don't see any tests using useFormikContext though. Maybe this is something we need to add? Or is validationSchema being passed via Formikbag enough proof that it's working? |
||
return null; | ||
}; | ||
|
||
render( | ||
<Formik | ||
initialValues={{ test: '' }} | ||
validationSchema={validationSchema} | ||
onSubmit={() => {}} | ||
> | ||
<AComponenent /> | ||
</Formik> | ||
); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add this to formikBag itself