2020-08-31 08:41:53 +09:00
|
|
|
import { render, waitFor } from '@testing-library/react';
|
|
|
|
import 'mutationobserver-shim';
|
|
|
|
import React from 'react';
|
|
|
|
import { useDeferredState } from './hooks';
|
2019-09-24 13:55:43 +09:00
|
|
|
|
|
|
|
const App: React.FC = () => {
|
2020-08-31 08:41:53 +09:00
|
|
|
const [value, setValue] = useDeferredState(500, 0);
|
2019-09-24 13:55:43 +09:00
|
|
|
React.useEffect(() => {
|
2020-08-31 08:41:53 +09:00
|
|
|
setValue(1);
|
|
|
|
setValue(2);
|
|
|
|
setValue(3);
|
|
|
|
}, [setValue]);
|
|
|
|
return <div data-testid="root">{value}</div>;
|
|
|
|
};
|
2019-09-24 13:55:43 +09:00
|
|
|
|
|
|
|
it('provoke state flow after certain time passed', async () => {
|
2020-08-31 08:41:53 +09:00
|
|
|
const { getByTestId } = render(<App />);
|
|
|
|
expect(getByTestId('root').textContent).toBe('0');
|
2020-03-14 12:02:22 +09:00
|
|
|
await waitFor(() => {
|
2020-08-31 08:41:53 +09:00
|
|
|
expect(getByTestId('root').textContent).toBe('3');
|
|
|
|
});
|
|
|
|
});
|