:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { hasField, readField, readPath } from './paths'
describe('paths', () => {
it('readField returns a present field and readPath walks nested segments', () => {
expect(readField({ role: 'user' }, 'role')).toBe('user')
expect(readPath({ a: { b: { c: 1 } } }, ['a', 'b', 'c'])).toBe(1)
})
it('hasField reports presence', () => {
expect(hasField({ role: 'user' }, 'role')).toBe(true)
expect(hasField({ role: undefined }, 'role')).toBe(true)
})
it('all return undefined/false for missing keys or non-object cursors', () => {
expect(readField({ a: 1 }, 'missing')).toBeUndefined()
expect(readField('not an object', 'length')).toBeUndefined()
expect(readPath({ a: {} }, ['a', 'b', 'c'])).toBeUndefined()
expect(hasField('not an object', 'length')).toBe(false)
})
})