import * as React from 'react'; import { cleanup, render } from '@testing-library/react'; import Freeze from '.'; const Example = ({ start }: { start: number }) => { const [state, setState] = React.useState(start); React.useEffect( () => { const interval = setInterval(() => { setState(old => old + 1) }, 5); return () => clearInterval(interval); }, [], ); return (
= 10}> {state}
); }; describe('Freeze component', () => { afterEach(cleanup); test('Should render children normally if enabled falsy', (finish) => { const { container } = render(); expect(container.textContent).toBe('0'); finish(); }); test('Should stops update children when enabled === true', (finish) => { const { container } = render(); setTimeout(() => { expect(container.textContent).toBe('10'); finish(); }, 1000); }); });