// import { fireEvent, render, waitFor } from "@testing-library/react"; // import { createForm } from "factory"; describe("createForm [ Validation ]", () => { // type SighUpForm = { // user: { // email: string; // password: string; // confirmPassword: string; // }; // }; // let formInstance = createForm({ // user: { // email: "", // password: "", // confirmPassword: "", // }, // }); beforeEach(() => { // formInstance = createForm({ // user: { // email: "", // password: "", // confirmPassword: "", // }, // }); }); // describe("when creating functional form", () => { // it("should allow to render fields and submit values", async () => { // const { Form, FormButton } = formInstance; // const onSubmit = jest.fn(); // const App = () => { // return ( //
// {/* // // */} // // Submit // // // ); // }; // const { getByTestId } = render(); // const emailInput = getByTestId("user.email"); // const passwordInput = getByTestId("user.password"); // const confirmPasswordInput = getByTestId("user.confirmPassword"); // const submitButton = getByTestId("submit"); // expect(emailInput).toBeDefined(); // expect(passwordInput).toBeDefined(); // expect(confirmPasswordInput).toBeDefined(); // expect(submitButton).toBeDefined(); // fireEvent.change(emailInput, { target: { value: "" } }); // fireEvent.change(passwordInput, { target: { value: "" } }); // fireEvent.change(confirmPasswordInput, { target: { value: "" } }); // fireEvent.click(submitButton); // await waitFor(() => { // expect(onSubmit).toHaveBeenCalledTimes(0); // expect(formInstance.form.store.getState().errors).toEqual({ // "user.email": { // errors: { required: "This field is required" }, // type: "required", // message: "This field is required", // valid: false, // }, // "user.password": { // errors: { required: "This is custom text" }, // type: "required", // message: "This is custom text", // valid: false, // }, // "user.confirmPassword": { // errors: {}, // type: "none", // message: "", // valid: true, // }, // }); // }); // }); // }); });