-
-
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
Problem with Jest and validationSchema #475
Comments
Probably related: facebook/create-react-app#3482 However, do you really need to render the whole It all comes to the last thing, what do you want to test? Do you really need to test |
If I change it to And I'm not trying to test handleChange, I'm trying to test that form cannot be submitted without valid values. Reason to test that is that maybe some developer changes name of the input but forgets to change related validation. |
You have two options then:
If you are unsure what is in your wrapper, you can have a look by |
|
This is how I got it finally working: it("submits when email is correct", done => {
const onSubmit = jest.fn();
const wrapper = mount(<App onSubmit={onSubmit} />);
wrapper.find('input[name="email"]').simulate("change", {
persist: jest.fn(),
target: { name: "email", value: "john.doe@test.com" }
});
wrapper.find("button").simulate("submit");
setTimeout(() => {
expect(onSubmit).toBeCalled();
done();
}, 0);
});
it("doesn't submit when email is incorrect", done => {
const onSubmit = jest.fn();
const wrapper = mount(<App onSubmit={onSubmit} />);
wrapper.find('input[name="email"]').simulate("change", {
persist: jest.fn(),
target: { name: "email", value: "john.doe.test.com" }
});
wrapper.find("button").simulate("submit");
setTimeout(() => {
expect(onSubmit).not.toBeCalled();
done();
}, 0);
}); For some reason I still don't understand the Thank you for you help @prichodko ! |
Glad to hear that 👍 |
Bug, Feature, or Question?
Question
Current Behavior
I have simple CRA app and after I added validationSchema to my form Jest started to throw this error:
Minimal project to reproduce problem: https://github.com/kpyorala/formik-yup
I just started to learning Jest so probably I'm doing something stupid but I don't understand what it is...
Desired Behavior
Passing test
Suggested Solutions
Additional Information
The text was updated successfully, but these errors were encountered: