mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-10-30 18:34:19 +00:00
Bulk rename across 989 files: - Package names: posthog-js → @hanzo/insights, posthog-node → @hanzo/insights-node, etc. - Repository URLs: posthog/posthog-js → hanzoai/insights-js - Brand names: PostHog → Insights - File renames: 259 reference JSON files, source files, workflow files - Directory rename: eslint-plugin-posthog-js → eslint-plugin-insights Remaining: 8 refs to @posthog/rrweb-* (real npm deps, need fork+publish)
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
/** @jest-environment jsdom */
|
|
import React from 'react'
|
|
import { renderHook } from '@testing-library/react'
|
|
import { InsightsContext } from '../src/InsightsContext'
|
|
import { useInsights } from '../src/hooks/useInsights'
|
|
import type { Insights } from '../src/insights-rn'
|
|
|
|
describe('useInsights', () => {
|
|
afterEach(() => {
|
|
jest.resetAllMocks()
|
|
})
|
|
|
|
it('should return the client from context', () => {
|
|
const mockInsights = {} as Insights
|
|
const wrapper = ({ children }: { children: React.ReactNode }) =>
|
|
React.createElement(InsightsContext.Provider, { value: { client: mockInsights } }, children)
|
|
|
|
const { result } = renderHook(() => useInsights(), { wrapper })
|
|
|
|
expect(result.current).toBe(mockInsights)
|
|
})
|
|
|
|
it('should log error when used outside a InsightsProvider', () => {
|
|
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {})
|
|
|
|
renderHook(() => useInsights())
|
|
|
|
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
expect.stringContaining('useInsights was called without a Insights client')
|
|
)
|
|
consoleErrorSpy.mockRestore()
|
|
})
|
|
})
|