Skip to content

Commit

Permalink
Add tests for initial person info
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Nov 26, 2024
1 parent 021f730 commit 04d783d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/__tests__/posthog-persistence.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference lib="dom" />
import { PostHogPersistence } from '../posthog-persistence'
import { SESSION_ID, USER_STATE } from '../constants'
import { INITIAL_PERSON_INFO, SESSION_ID, USER_STATE } from '../constants'
import { PostHogConfig } from '../types'
import Mock = jest.Mock
import { PostHog } from '../posthog-core'
Expand Down Expand Up @@ -160,6 +160,15 @@ describe('persistence', () => {
})}`
)

lib.register({ [INITIAL_PERSON_INFO]: { u: 'https://www.example.com', r: 'https://www.referrer.com' } })
expect(document.cookie).toContain(
`ph__posthog=${encode({
distinct_id: 'test',
$sesid: [1000, 'sid', 2000],
$initial_person_info: { u: 'https://www.example.com', r: 'https://www.referrer.com' },
})}`
)

// Clear localstorage to simulate being on a different domain
localStorage.clear()

Expand All @@ -168,6 +177,7 @@ describe('persistence', () => {
expect(newLib.props).toEqual({
distinct_id: 'test',
$sesid: [1000, 'sid', 2000],
$initial_person_info: { u: 'https://www.example.com', r: 'https://www.referrer.com' },
})
})

Expand Down

0 comments on commit 04d783d

Please sign in to comment.