Merge branch 'fix-typo-drive' into 'main'
[ProtonMail-WebClient.git] / packages / hooks / useStateRef.test.ts
blob95306df07a698f3d640e5c13812fb7f946875210
1 import { act, renderHook } from '@testing-library/react-hooks';
3 import { useStateRef } from '@proton/hooks';
5 describe('useStateRef', () => {
6     it('should update ref when state is updated', () => {
7         const hook = renderHook(() => useStateRef(0));
9         act(() => {
10             const [, dispatch] = hook.result.current;
11             dispatch(1);
12         });
14         const [state, , ref] = hook.result.current;
16         expect(state).toEqual(1);
17         expect(ref.current).toEqual(1);
18     });
20     it('should update ref when state is updated with function', () => {
21         const hook = renderHook(() => useStateRef(0));
23         act(() => {
24             const [, dispatch] = hook.result.current;
25             dispatch((prev) => prev + 1);
26         });
28         const [state, , ref] = hook.result.current;
30         expect(state).toEqual(1);
31         expect(ref.current).toEqual(1);
32     });
33 });