Skip to content

Update example-formik.md #692

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

Merged
merged 1 commit into from
Nov 27, 2020
Merged

Conversation

dandelionadia
Copy link
Contributor

onSubmit has two arguments and we need to ignore the second one. (https://formik.org/docs/api/formik#onsubmit-values-values-formikbag-formikbag--void--promiseany)
If we do not do this then we will get an error:

expect(jest.fn()).toHaveBeenCalledWith(...expected)

    - Expected
    + Received

      {"email": "[email protected]", "password": "password2398"},
    + {"resetForm": [Function anonymous], "setErrors": [Function anonymous], "setFieldError": [Function anonymous], "setFieldTouched": [Function anonymous], "setFieldValue": [Function anonymous], "setFormikState": [Function anonymous], "setStatus": [Function anonymous], "setSubmitting": [Function anonymous], "setTouched": [Function anonymous], "setValues": [Function anonymous], "submitForm": [Function anonymous], "validateField": [Function anonymous], "validateForm": [Function anonymous]},

onSubmit has two arguments and we need to ignore the second one. (https://formik.org/docs/api/formik#onsubmit-values-values-formikbag-formikbag--void--promiseany)
If we do not do this then we will get an error: 
```
expect(jest.fn()).toHaveBeenCalledWith(...expected)

    - Expected
    + Received

      {"email": "[email protected]", "password": "password2398"},
    + {"resetForm": [Function anonymous], "setErrors": [Function anonymous], "setFieldError": [Function anonymous], "setFieldTouched": [Function anonymous], "setFieldValue": [Function anonymous], "setFormikState": [Function anonymous], "setStatus": [Function anonymous], "setSubmitting": [Function anonymous], "setTouched": [Function anonymous], "setValues": [Function anonymous], "submitForm": [Function anonymous], "validateField": [Function anonymous], "validateForm": [Function anonymous]},
```
Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I thought jest would default to ignoring excess args. But it does indeed fail if not every arg is asserted on: https://codesandbox.io/s/winter-dream-g87iv?file=/src/index.test.js.

@eps1lon eps1lon merged commit e8524e8 into testing-library:master Nov 27, 2020
eps1lon added a commit to eps1lon/testing-library-docs that referenced this pull request Jun 29, 2021
@eps1lon
Copy link
Member

eps1lon commented Jun 29, 2021

We're reverting this change in #876

We didn't expose the formik bag to begin with. The assertion is only needed if you do pass the formik bag to onSubmit which we're not doing in the demo.

eps1lon added a commit that referenced this pull request Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants