用Jest模拟包装器React Hook

我正在尝试使用不同的方式来使用和测试React挂钩。我正在考虑的一种方法是如何模拟包装另一个钩子的通用钩子?这应该相对简单,因为包装钩利用了回调钩子/功能。例如,

// customhooks.js
const useWrapperHook = (hook, params) => hook(params)

// my component.js
import {useAnotherHook) from "thirdParyHook"

const MyComponent = props => {

  useWrapperHook(useAnotherHook)

  return (/* ... */)

}

I want to be able to mock useWrapperHook and stub a response in Jest. For instance, the code above would allow the test to substitute anotherHook for a stub:


const stubbedHookResponseObject = {id: 1}
const stubbedWrappedHook = () => stubbedHookResponseObject

// ... ??? How to mock useWrapperHook and use `stubbedWrappedHook` in `MyComponent` instead of `useAnotherHook`

const rendered = shallow<MyComponent />

I've tried all the following and nothing seems to work ... useAnotherHook is stilled called when the test is triggered:

// jest.mock(useHookWrapper) // Doesn't work

// jest.mock('./../customhooks', () => ({
//     __esModule: true,
//     useHookWrapper: jest.fn(stubbedWrappedHook)
// })) // Doesn't work

// const utils = jest.genMockFromModule('./../customhooks'); // Desperate attempt and doesn't work

I can certainly stub useAnotherHook but I didn't want to test at this level; I just want to stub the input going into useWrapperHook and stub the response. Any thoughts? Thanks.