UNPKG

746 BJavaScriptView Raw
1import React from 'react';
2import { render, cleanup, waitFor } from '@testing-library/react';
3import { useTimeout } from '..';
4
5afterEach(cleanup);
6
7// eslint-disable-next-line react/prop-types
8const Component = () => {
9 const timeout = useTimeout(1000);
10
11 return <p data-testid="timeout-test">{timeout ? 'True' : 'False'}</p>;
12};
13
14describe('useTimeout', () => {
15 test('should render "False"', () => {
16 const { getByTestId } = render(<Component />);
17
18 expect(getByTestId('timeout-test').textContent).toEqual('False');
19 });
20
21 test('should render "True"', async () => {
22 const { getByTestId } = render(<Component />);
23
24 await waitFor(() => {
25 expect(getByTestId('timeout-test').textContent).toEqual('True');
26 });
27 });
28});
29
\No newline at end of file