1 | import React from 'react';
|
2 | import { render, cleanup, wait } from '@testing-library/react';
|
3 | import { useTimeout } from '..';
|
4 |
|
5 | afterEach(cleanup);
|
6 |
|
7 |
|
8 | const Component = () => {
|
9 | const timeout = useTimeout(1000);
|
10 |
|
11 | return <p data-testid="timeout-test">{timeout ? 'True' : 'False'}</p>;
|
12 | };
|
13 |
|
14 | describe('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 wait(() => {
|
25 | expect(getByTestId('timeout-test').textContent).toEqual('True');
|
26 | });
|
27 | });
|
28 | });
|
29 |
|
\ | No newline at end of file |