mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
chore: move all the tests to the separate directory outside of sources; chore: remove jest.config.js (config moved to the package.json); test: unused import in test; test: 💍 fix tests add back x and y to useMeasure chore: 🤖 add linter to /tests folder ci: 🎡 limit Jest worker count for CircleCI
29 lines
836 B
TypeScript
29 lines
836 B
TypeScript
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();
|
|
});
|
|
});
|