-
Notifications
You must be signed in to change notification settings - Fork 231
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Describe the feature you'd like:
I think the renderHook interface is a bit clumbersome, especially when working with custom hooks with arguments.
Suggested implementation:
I have created a Typescript wrapper to simplify the unit testing code
// Test utilty for custom hooks with effects.
// Usage:
// const hook = renderCustomHook(useMyHook, TypedArd1, TypeArg2, TypedArg3...);
//
// assert results from: hook.result
// use hook.rerender(typed arguments) to update hook.
export function renderCustomHook<T extends any[], R>(
theHook: (...args: T) => R,
...args: T
): {
readonly result: HookResult<R>;
readonly waitForNextUpdate: () => Promise<void>;
readonly unmount: () => boolean;
readonly rerender: (...args: T) => void;
};
export function renderCustomHook(theHook: (...args: any[]) => any, ...args: any[]) {
const hook = renderHook((param: { props: any[] }) => theHook(...param.props), {
initialProps: { props: args },
});
return { ...hook, rerender: (...args: any[]) => hook.rerender({ props: args }) };
}Describe alternatives you've considered:
Would it be possible to include something like this in the library?
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request