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
43
44
|
import { act, renderHook } from '@testing-library/react';
import type { FC, ReactNode } from 'react';
import type { AckeeTrackerValue } from '../../../types';
import { AckeeProvider, type AckeeProviderProps } from '../../providers';
import { useAckee } from './use-ackee';
const createWrapper = (
Wrapper: FC<AckeeProviderProps>,
config: AckeeProviderProps
) =>
function CreatedWrapper({ children }: { children: ReactNode }) {
return <Wrapper {...config}>{children}</Wrapper>;
};
describe('useAckee', () => {
it('should return the default value without provider and prevent update', () => {
const { result } = renderHook(() => useAckee());
expect(result.current[0]).toBe('full');
act(() => result.current[1]());
expect(result.current[0]).toBe('full');
});
it('can update the value', () => {
const defaultValue: AckeeTrackerValue = 'full';
const { result } = renderHook(() => useAckee(), {
wrapper: createWrapper(AckeeProvider, {
domainId: 'some-id',
server: 'https://example.com',
storageKey: 'veniam',
tracking: defaultValue,
}),
});
expect(result.current[0]).toBe(defaultValue);
act(() => result.current[1]());
expect(result.current[0]).toBe('partial');
});
});
|