I have a component, with the following function inside of it:
const RolloutPage = () => {
const getServiceHistory = async (serviceName, account) => {
};
}
export default withRouter(RolloutPage);
How can i mock the inside function? I have tried:
jest.spyOn(<RolloutPage/>, 'getServiceHistory').mockImplementation(() =>
Promise.resolve({
json: () => Promise.resolve({ serviceTimelineDataMock }),
})
);
render(
<MemoryRouter>
<PageErrorBoundary>
<RolloutPage />
</PageErrorBoundary>
</MemoryRouter>
)
But it gives me the following error:
Cannot spy the getServiceHistory property because it is not a function; undefined given instead
I have tried some of the other answers here in SO, but none of them worked.