flat-fuchsia
flat-fuchsia2y ago

How to mock useForm queryResult only?

HI. Currently i have this code. Im mocking queryResult.
jest.mock('@pankod/refine-antd', () => ({
...(jest.requireActual('@pankod/refine-antd')),
useForm: () => {
return {
queryResult: {
data: {
data: {
name: ''
}
},
isLoading: true
}
}
}
}))
jest.mock('@pankod/refine-antd', () => ({
...(jest.requireActual('@pankod/refine-antd')),
useForm: () => {
return {
queryResult: {
data: {
data: {
name: ''
}
},
isLoading: true
}
}
}
}))
The problem is that, i need to retain the formprops and saveButtonProps i only need to mock the queryResult. How can i do it ?
1 Reply
refine-support-bot
Hi, I am refine support bot :wave:. I am here to help you with your question. I searched for the answer to your question in the refine documentation and found an answer! 🏆
Answer: You can mock useForm by using the following code: jest.mock('@pankod/refine-antd', () => ({ ...(jest.requireActual('@pankod/refine-antd')), useForm: () => { return { queryResult: { data: { data: { name: '' } }, isLoading: true }, saveButtonProps: {}, refineCore: { queryResult: {}, ... // @pankod/refine-core's useForm return values }, } } })) SOURCES: ./docs/api-reference/mantine/hooks/form/useForm.md, ./docs/examples/form/react-hook-form/useForm.md, ./docs/examples/form/mui/useForm.md

Note: If this is the answer you need, then we are very lucky. If not, please wait for someone from the refine core team or the community to try to help you.

Did you find this page helpful?