-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseDualScrollSyncContext.test.tsx
More file actions
42 lines (36 loc) · 1.13 KB
/
useDualScrollSyncContext.test.tsx
File metadata and controls
42 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { renderHook } from '@testing-library/react';
import type { FC, PropsWithChildren } from 'react';
import { vi } from 'vitest';
import { DualScrollSyncContext } from '@/contexts';
import { useDualScrollSyncContext } from './useDualScrollSyncContext';
const mockValue = {
contentId: 'test',
baseId: '',
navId: '',
activeKey: null,
contentRef: { current: null },
navItemRefs: { current: {} },
navRef: { current: null },
sectionRefs: { current: {} },
onMenuItemSelect: vi.fn(),
onItemClick: vi.fn(),
maxVisibleItems: 6
};
const Wrapper: FC<PropsWithChildren> = ({ children }) => {
return (
<DualScrollSyncContext.Provider value={mockValue}>{children}</DualScrollSyncContext.Provider>
);
};
describe('useDualScrollSyncContext', () => {
it('throws when used outside of provider', () => {
expect(() => renderHook(() => useDualScrollSyncContext())).toThrow(
'DualScrollSync.* must be used within <DualScrollSync>'
);
});
it('returns context when used inside provider', () => {
const { result } = renderHook(() => useDualScrollSyncContext(), {
wrapper: Wrapper
});
expect(result.current).toBe(mockValue);
});
});