Created
October 26, 2021 16:13
-
-
Save sheppardjm/d268f7e9c653bcffa25a2387c85180dc to your computer and use it in GitHub Desktop.
Mocking Formik connect HOC and useFormikContext for Jest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mockInitialValue = { test: "" }; | |
const mockSetValue = { test: "" }; | |
const mockErrors = { test: "" }; | |
jest.mock("../path/to/formik", () => ({ | |
useFormikContext: jest.fn().mockImplementation(() => { | |
return { | |
setFieldValue: () => { | |
return mockSetValue; | |
}, | |
values: mockInitialValue, //allowed if named ^mock{LowerCamel} | |
errors: mockErrors, | |
}; | |
}), | |
connect: (Component) => (props) => { | |
return <Component {...props} />; | |
}, | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment