Created
September 25, 2020 19:35
-
-
Save adamjarling/4d8a4b3b30a93245d1feeb7cc5934d36 to your computer and use it in GitHub Desktop.
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
/** | |
* Testing Library utility function to wrap tested component in React Hook Form | |
* @param {ReactElement} ui A React component | |
* @param objectParameters | |
* @param {Object} objectParameters.defaultValues Initial form values to pass into | |
* React Hook Form, which you can then assert against | |
*/ | |
export function renderWithReactHookForm( | |
ui, | |
{ defaultValues = {} } = {} | |
) { | |
let reactHookFormMethods = {}; | |
const Wrapper = ({ children }) => { | |
const methods = useForm({ defaultValues }); | |
return <FormProvider {...methods}>{children}</FormProvider>; | |
}; | |
return { | |
...render(ui, { wrapper: Wrapper }) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment