1
0
mirror of https://github.com/uetchy/namae.git synced 2025-07-04 07:10:03 +09:00
namae/src/util/hooks.test.tsx

23 lines
637 B
TypeScript

import React from 'react';
import {render, waitFor} from '@testing-library/react';
import {useDeferredState} from './hooks';
import 'mutationobserver-shim';
const App: React.FC = () => {
const [value, setValue] = useDeferredState(500, 0);
React.useEffect(() => {
setValue(1);
setValue(2);
setValue(3);
}, [setValue]);
return <div data-testid="root">{value}</div>;
};
it('provoke state flow after certain time passed', async () => {
const {getByTestId} = render(<App />);
expect(getByTestId('root').textContent).toBe('0');
await waitFor(() => {
expect(getByTestId('root').textContent).toBe('3');
});
});