mirror of
https://github.com/streamich/react-use.git
synced 2026-01-25 14:17:16 +00:00
22 lines
694 B
TypeScript
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);
|
|
});
|
|
});
|