import * as React from 'react' import { render } from '@testing-library/react' import { PostHogProvider } from '../PostHogProviderSlim' import { PostHogContext } from '../PostHogContext' import type { PostHog } from 'posthog-js' // Do NOT call setDefaultPostHogInstance — this simulates the slim bundle // where no default instance exists. let contextClient: PostHog | undefined function ClientConsumer() { const { client } = React.useContext(PostHogContext) contextClient = client return
consumed
} describe('PostHogProvider (slim)', () => { afterEach(() => { contextClient = undefined }) it('renders children', () => { const client = { config: {} } as unknown as PostHog const { getByText } = render(
Hello
) expect(getByText('Hello')).toBeTruthy() }) it('provides the exact client instance via context', () => { const client = { config: {} } as unknown as PostHog render( ) expect(contextClient).toBe(client) }) it('provides bootstrap from client config', () => { const bootstrap = { featureFlags: { 'test-flag': true } } const client = { config: { bootstrap } } as unknown as PostHog function BootstrapConsumer() { const { bootstrap: ctx } = React.useContext(PostHogContext) return
{JSON.stringify(ctx)}
} const { getByTestId } = render( ) expect(JSON.parse(getByTestId('bootstrap').textContent!)).toEqual(bootstrap) }) })