Closed
Description
Hey guys,
I'm sorry, i'm not very confortable with other testing libraries, and i cannot get how to test my hooks with this library.
I have a very simple hook, which wait for visibility to store a timestamp of render time, which will never update after that :
export function useRenderedAt(isViewable: boolean) {
const [renderedAt, setRenderedAt] = React.useState(Infinity);
React.useEffect(() => {
if (isViewable) {
setRenderedAt(Date.now());
}
}, [isViewable]);
return renderedAt;
}
I'm trying to test it this way :
test.only('should return render time when viewable', done => {
const hook = renderHook(() => useRenderedAt(false), {
initialProps: false
});
expect(hook.result.current).toBe(Infinity);
hook.waitForNextUpdate().then(() => {
expect(hook.result.current).not.toBe(Infinity);
done();
});
hook.rerender(true);
});
What am i doing wrong ?