Closed
Description
I have an effect that uses setInterval
. In order for my tests to work right, I need to unmount
so the interval gets knocked away.
I have code like this:
let globalUnmount;
// I use this is all of my tests to run render the hook
async function runEffects(wait = true) {
const { result, unmount } = renderHook(() =>
useMyHookWithIntervals()
);
globalUnmount = unmount;
return {
result
};
}
afterEach(() => {
if (globalUnmount) {
globalUnmount();
globalUnmount = null;
}
});
Is this the expected paradigm? Is this an example that would be good for docs? Is this horrible?