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();
12 * TODO: expected this to return false if the callback
13 * returned from renderHook is called immediately, however
14 * this is true it seems.
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.
20 * This is probably an issue with @testing-library/react-hooks.
22 * The test below also doesn't really make sense given this
23 * as it's true both before and after the act() call.
25 // expect(isMounted).toBe(false);
26 expect(isMounted).toBe(true);
29 it('returns true after mount', () => {
30 const hook = renderHook(() => useIsMounted());
34 const isMounted = hook.result.current();
36 expect(isMounted).toBe(true);