diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-10-26 21:55:55 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:15:27 +0100 |
| commit | 3ab9f0423e97af63da4bf6a13ffd786955bd5b3b (patch) | |
| tree | 53866337f2e2b0bd47ada82f0f35799595663108 /src/utils/hooks/use-ackee/use-ackee.test.tsx | |
| parent | 795b92cc1a168c48c7710ca6e0e1ef5974013d95 (diff) | |
refactor(hooks,providers): rewrite useAckee hook and AckeeProvider
Diffstat (limited to 'src/utils/hooks/use-ackee/use-ackee.test.tsx')
| -rw-r--r-- | src/utils/hooks/use-ackee/use-ackee.test.tsx | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/utils/hooks/use-ackee/use-ackee.test.tsx b/src/utils/hooks/use-ackee/use-ackee.test.tsx new file mode 100644 index 0000000..230fe0b --- /dev/null +++ b/src/utils/hooks/use-ackee/use-ackee.test.tsx @@ -0,0 +1,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'); + }); +}); |
