react-use/tests/createGlobalState.test.ts
Renovate Bot a27f09fd36
chore: refactoring and rearrangement.
More DRY code. Also move non-hooks to separate directories.

BREAKING CHANGE: all `create*` factories been moved to `factory` subdirectory and in case direct import should be imported like `react-use/esm/factory/createBreakpoint`
BREAKING CHANGE: `comps` directory renamed to `component`
2021-01-30 23:30:26 +03:00

22 lines
702 B
TypeScript

import { act, renderHook } from '@testing-library/react-hooks';
import createGlobalState from '../src/factory/createGlobalState';
describe('useGlobalState', () => {
it('should be defined', () => {
expect(createGlobalState).toBeDefined();
});
it('both components should be updated', () => {
const useGlobalValue = createGlobalState(0);
const { result: result1 } = renderHook(() => useGlobalValue());
const { result: result2 } = renderHook(() => useGlobalValue());
expect(result1.current[0] === 0);
expect(result2.current[0] === 0);
act(() => {
result1.current[1](1);
});
expect(result1.current[0] === 1);
expect(result2.current[0] === 1);
});
});