@@ -19,5 +19,74 @@ describe('PostHog React Native', () => {
1919 autocaptureFromTouchEvent ( { _targetInst : ignoreEvent , nativeEvent } , mockPostHog )
2020 expect ( mockPostHog . autocapture ) . toHaveBeenCalledTimes ( 0 )
2121 } )
22+
23+ it ( 'should handle animated styles without errors' , ( ) => {
24+ const mockPostHog = { autocapture : jest . fn ( ) } as any
25+
26+ // Mock a Reanimated animated style
27+ const animatedStyle = {
28+ _isReanimatedSharedValue : true ,
29+ _value : { opacity : 1 } ,
30+ __reanimatedHostObjectRef : { } ,
31+ }
32+
33+ const eventWithAnimatedStyle = {
34+ _targetInst : {
35+ elementType : { name : 'TouchableOpacity' } ,
36+ memoizedProps : {
37+ style : animatedStyle ,
38+ children : 'Test Button' ,
39+ } ,
40+ return : null ,
41+ } ,
42+ nativeEvent,
43+ }
44+
45+ // Should not throw error when processing animated styles
46+ expect ( ( ) => {
47+ autocaptureFromTouchEvent ( eventWithAnimatedStyle , mockPostHog )
48+ } ) . not . toThrow ( )
49+
50+ // Should still capture the event, just with empty style
51+ expect ( mockPostHog . autocapture ) . toHaveBeenCalledTimes ( 1 )
52+ const capturedElement = mockPostHog . autocapture . mock . calls [ 0 ] [ 1 ] [ 0 ]
53+ expect ( capturedElement . attr__style ) . toBe ( '' )
54+ expect ( capturedElement . $el_text ) . toBe ( 'Test Button' )
55+ } )
56+
57+ it ( 'should handle mixed animated and regular styles' , ( ) => {
58+ const mockPostHog = { autocapture : jest . fn ( ) } as any
59+
60+ const mixedStyle = [
61+ { backgroundColor : 'red' , padding : 10 } ,
62+ {
63+ opacity : {
64+ _isReanimatedSharedValue : true ,
65+ _value : 1 ,
66+ } ,
67+ } ,
68+ ]
69+
70+ const eventWithMixedStyle = {
71+ _targetInst : {
72+ elementType : { name : 'View' } ,
73+ memoizedProps : {
74+ style : mixedStyle ,
75+ testID : 'test-view' ,
76+ } ,
77+ return : null ,
78+ } ,
79+ nativeEvent,
80+ }
81+
82+ autocaptureFromTouchEvent ( eventWithMixedStyle , mockPostHog )
83+
84+ expect ( mockPostHog . autocapture ) . toHaveBeenCalledTimes ( 1 )
85+ const capturedElement = mockPostHog . autocapture . mock . calls [ 0 ] [ 1 ] [ 0 ]
86+ // Should capture regular styles but skip animated values
87+ expect ( capturedElement . attr__style ) . toContain ( 'backgroundColor:red' )
88+ expect ( capturedElement . attr__style ) . toContain ( 'padding:10' )
89+ expect ( capturedElement . attr__style ) . not . toContain ( 'opacity' )
90+ } )
2291 } )
2392} )
0 commit comments