-
-
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?
add validationSchema to FormikContext #2090
Conversation
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/jared/formik-docs/1dgk3anhx |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit e5a3cc3:
|
Also hitting the same issue, if anything is needed to help, please let me know. |
@ldicocco also it probably worth to add
you can see that both @ldicocco @josejulio is there any workaround to get @jaredpalmer is it possible to merge this one and release as otherwise formik is broken in case someone is using yup metadata to get the desired UI |
cmon please merge it! There is no chance to dynamically check if come field is required or not and render it to UI !!! |
please merge it ! |
@josejulio What about workaround ? |
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.
Some small changes requested.
Testing useFormikContext may need further thought, unless it is acceptable to test props.
<FormikProvider | ||
value={{ | ||
...formikbag, | ||
validationSchema, |
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
|
||
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 comment
The 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?
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 comment
The reason will be displayed to describe this comment to others. Learn more.
is string
valid for validation schema? thought it had to be a Yup object. Other tests use { validate: jest.fn(() => Promise.resolve()) }
.
I used the validation schema that I knew was in place directly. |
Can someone please merge/fix this? It is a very crucial missing feature right now... |
Hello! Any news on this? Thanks! |
This is a very important feature, I hope it gets merged soon. |
useFormikContext
doesn't returnvalidationSchema,
although the type says it should do and theconnect
in v1 did.This PR fixes the problem and adds a specific test for this case.