mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
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`
22 lines
702 B
TypeScript
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);
|
|
});
|
|
});
|