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

23 lines
643 B
TypeScript
Raw Normal View History

2020-06-29 12:24:01 +09:00
import { render, waitFor } from '@testing-library/react';
2020-03-14 12:02:22 +09:00
import 'mutationobserver-shim';
2020-06-29 12:24:01 +09:00
import React from 'react';
import { useDeferredState } from './hooks';
2019-09-24 13:55:43 +09:00
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 () => {
2020-06-29 12:24:01 +09:00
const { getByTestId } = render(<App />);
2019-09-24 13:55:43 +09:00
expect(getByTestId('root').textContent).toBe('0');
2020-03-14 12:02:22 +09:00
await waitFor(() => {
expect(getByTestId('root').textContent).toBe('3');
});
2019-09-24 13:55:43 +09:00
});