File size: 836 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import { renderHook } from '@testing-library/react-hooks';
import useMountedState from '../src/useMountedState';
describe('useMountedState', () => {
it('should be defined', () => {
expect(useMountedState).toBeDefined();
});
it('should return a function', () => {
const hook = renderHook(() => useMountedState(), { initialProps: false });
expect(typeof hook.result.current).toEqual('function');
});
it('should return true if component is mounted', () => {
const hook = renderHook(() => useMountedState(), { initialProps: false });
expect(hook.result.current()).toBeTruthy();
});
it('should return false if component is unmounted', () => {
const hook = renderHook(() => useMountedState(), { initialProps: false });
hook.unmount();
expect(hook.result.current()).toBeFalsy();
});
});
|