Merge branch 'fix-typo-drive' into 'main'
[ProtonMail-WebClient.git] / packages / hooks / useIsMounted.test.ts
blob63ccc4424b6732fb03fdcd7dce53175822715192
1 import { act, renderHook } from '@testing-library/react-hooks';
3 import useIsMounted from './useIsMounted';
5 describe('useIsMounted()', () => {
6     it('returns false initially', () => {
7         const hook = renderHook(() => useIsMounted());
9         const isMounted = hook.result.current();
11         /**
12          * TODO: expected this to return false if the callback
13          * returned from renderHook is called immediately, however
14          * this is true it seems.
15          *
16          * Tried removing the useCallback from inside useIsMounted,
17          * tried removing the callback entirely and just returning
18          * the ref directly, but it's true every time.
19          *
20          * This is probably an issue with @testing-library/react-hooks.
21          *
22          * The test below also doesn't really make sense given this
23          * as it's true both before and after the act() call.
24          */
25         // expect(isMounted).toBe(false);
26         expect(isMounted).toBe(true);
27     });
29     it('returns true after mount', () => {
30         const hook = renderHook(() => useIsMounted());
32         act(() => {});
34         const isMounted = hook.result.current();
36         expect(isMounted).toBe(true);
37     });
38 });