react-use/tests/createGlobalState.test.ts
2020-01-13 09:45:52 +08:00

22 lines
694 B
TypeScript

import { act, renderHook } from '@testing-library/react-hooks';
import createGlobalState from '../src/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);
});
});