const Component = ({onSend}) => {
const { countdown, start, reset, isRunning } = useCountdownTimer({
timer: 1000 * 30,
});
const handleSubmit = useCallback(
(values) => {
onSend(values.phone);
reset();
start();
},
[start, reset, onSend];
);
return (
<Button onClick={handleSubmit} disabled={isRunning}>Submit {countdown / 1000}</Button>
);
}
expect(submitButton).toBeDisabled();
act(() => {
jest.advanceTimersByTime(31000);
});
expect(submitButton).toBeEnabled();
I found out that timer doesn't stop in this case, it shows 0 seconds, then -1 second, -2 seconds and so on...