22import { render } from '@testing-library/react-native' ;
33import * as React from 'react' ;
44import type { ReactNativeWrapperOptions } from 'src/js/options' ;
5+ import * as environment from '../src/js/utils/environment' ;
56
67jest . doMock ( '../src/js/touchevents' , ( ) => {
78 return {
8- TouchEventBoundary : ( { children } : { children : React . ReactNode } ) => (
9- // eslint-disable-next-line react/no-unknown-property
10- < div testID = "touch-boundaryID" > { children } </ div >
11- ) ,
12- }
9+ TouchEventBoundary : ( { children } : { children : React . ReactNode } ) => (
10+ // eslint-disable-next-line react/no-unknown-property
11+ < div testID = "touch-boundaryID" > { children } </ div >
12+ ) ,
13+ } ;
1314} ) ;
1415
1516jest . doMock ( '../src/js/tracing' , ( ) => {
1617 return {
17- ReactNativeProfiler : jest . fn ( ( { children } : { children : React . ReactNode } ) => (
18- // eslint-disable-next-line react/no-unknown-property
19- < div testID = "profilerID" > { children } </ div >
20- ) ) ,
21- }
18+ ReactNativeProfiler : jest . fn ( ( { children } : { children : React . ReactNode } ) => (
19+ // eslint-disable-next-line react/no-unknown-property
20+ < div testID = "react-native-profilerID" > { children } </ div >
21+ ) ) ,
22+ } ;
23+ } ) ;
24+
25+ jest . doMock ( '@sentry/react' , ( ) => {
26+ return {
27+ Profiler : jest . fn ( ( { children } : { children : React . ReactNode } ) => (
28+ // eslint-disable-next-line react/no-unknown-property
29+ < div testID = "react-profilerID" > { children } </ div >
30+ ) ) ,
31+ } ;
2232} ) ;
2333
2434jest . doMock ( '../src/js/feedback/FeedbackWidgetProvider' , ( ) => {
@@ -34,26 +44,50 @@ import { wrap } from '../src/js/sdk';
3444import { ReactNativeProfiler } from '../src/js/tracing' ;
3545
3646describe ( 'Sentry.wrap' , ( ) => {
47+ const DummyComponent : React . FC < { value ?: string } > = ( { value } ) => < div > { value } </ div > ;
3748
38- const DummyComponent : React . FC < { value ?: string } > = ( { value } ) => < div > { value } </ div > ;
49+ it ( 'should not enforce any keys on the wrapped component' , ( ) => {
50+ const Mock : React . FC < { test : 23 } > = ( ) => < > </ > ;
51+ const ActualWrapped = wrap ( Mock ) ;
3952
40- it ( 'should not enforce any keys on the wrapped component' , ( ) => {
41- const Mock : React . FC < { test : 23 } > = ( ) => < > </ > ;
42- const ActualWrapped = wrap ( Mock ) ;
53+ expect ( typeof ActualWrapped . defaultProps ) . toBe ( typeof Mock . defaultProps ) ;
54+ } ) ;
4355
44- expect ( typeof ActualWrapped . defaultProps ) . toBe ( typeof Mock . defaultProps ) ;
45- } ) ;
56+ it ( 'wraps components with Sentry wrappers' , ( ) => {
57+ const Wrapped = wrap ( DummyComponent ) ;
58+ const renderResult = render ( < Wrapped value = "wrapped" /> ) ;
4659
47- it ( 'wraps components with Sentry wrappers' , ( ) => {
48- const Wrapped = wrap ( DummyComponent ) ;
49- const renderResult = render ( < Wrapped value = "wrapped" /> ) ;
60+ expect ( renderResult . toJSON ( ) ) . toMatchInlineSnapshot ( `
61+ <div
62+ testID="touch-boundaryID"
63+ >
64+ <div
65+ testID="react-native-profilerID"
66+ >
67+ <div
68+ testID="feedback-widgetID"
69+ >
70+ <div>
71+ wrapped
72+ </div>
73+ </div>
74+ </div>
75+ </div>
76+ ` ) ;
77+ } ) ;
78+
79+ it ( 'wraps components with JS React Profiler on web' , ( ) => {
80+ jest . spyOn ( environment , 'isWeb' ) . mockReturnValueOnce ( true ) ;
5081
51- expect ( renderResult . toJSON ( ) ) . toMatchInlineSnapshot ( `
82+ const Wrapped = wrap ( DummyComponent ) ;
83+ const renderResult = render ( < Wrapped value = "wrapped" /> ) ;
84+
85+ expect ( renderResult . toJSON ( ) ) . toMatchInlineSnapshot ( `
5286 <div
5387 testID="touch-boundaryID"
5488 >
5589 <div
56- testID="profilerID"
90+ testID="react- profilerID"
5791 >
5892 <div
5993 testID="feedback-widgetID"
@@ -65,46 +99,46 @@ describe('Sentry.wrap', () => {
6599 </div>
66100 </div>
67101` ) ;
102+ } ) ;
103+
104+ describe ( 'ReactNativeProfiler' , ( ) => {
105+ it ( 'uses given options when set' , ( ) => {
106+ const options : ReactNativeWrapperOptions = {
107+ profilerProps : { disabled : false , includeRender : true , includeUpdates : true } ,
108+ } ;
109+ const Wrapped = wrap ( DummyComponent , options ) ;
110+ render ( < Wrapped value = "wrapped" /> ) ;
111+
112+ expect ( ReactNativeProfiler ) . toHaveBeenCalledWith (
113+ expect . objectContaining ( {
114+ name : 'Root' ,
115+ disabled : false ,
116+ includeRender : true ,
117+ includeUpdates : true ,
118+ } ) ,
119+ expect . anything ( ) ,
120+ ) ;
121+
122+ expect ( ReactNativeProfiler ) . not . toHaveBeenCalledWith (
123+ expect . objectContaining ( {
124+ updateProps : expect . anything ( ) ,
125+ } ) ,
126+ ) ;
68127 } ) ;
69128
70- describe ( 'ReactNativeProfiler' , ( ) => {
71- it ( 'uses given options when set' , ( ) => {
72- const options : ReactNativeWrapperOptions = {
73- profilerProps : { disabled : false , includeRender : true , includeUpdates : true } ,
74- } ;
75- const Wrapped = wrap ( DummyComponent , options ) ;
76- render ( < Wrapped value = "wrapped" /> ) ;
77-
78- expect ( ReactNativeProfiler ) . toHaveBeenCalledWith (
79- expect . objectContaining ( {
80- name : 'Root' ,
81- disabled : false ,
82- includeRender : true ,
83- includeUpdates : true
84- } ) ,
85- expect . anything ( ) ,
86- ) ;
87-
88- expect ( ReactNativeProfiler ) . not . toHaveBeenCalledWith (
89- expect . objectContaining ( {
90- updateProps : expect . anything ( ) ,
91- } )
92- ) ;
93- } ) ;
94-
95- it ( 'ignore updateProps when set' , ( ) => {
96- const { wrap } = jest . requireActual ( '../src/js/sdk' ) ;
97-
98- const Wrapped = wrap ( DummyComponent , { updateProps : [ 'prop' ] } ) ;
99- render ( < Wrapped value = "wrapped" /> ) ;
100-
101- expect ( ReactNativeProfiler ) . toHaveBeenCalledWith (
102- expect . objectContaining ( {
103- name : 'Root' ,
104- updateProps : { } ,
105- } ) ,
106- expect . anything ( ) ,
107- ) ;
108- } ) ;
129+ it ( 'ignore updateProps when set' , ( ) => {
130+ const { wrap } = jest . requireActual ( '../src/js/sdk' ) ;
131+
132+ const Wrapped = wrap ( DummyComponent , { updateProps : [ 'prop' ] } ) ;
133+ render ( < Wrapped value = "wrapped" /> ) ;
134+
135+ expect ( ReactNativeProfiler ) . toHaveBeenCalledWith (
136+ expect . objectContaining ( {
137+ name : 'Root' ,
138+ updateProps : { } ,
139+ } ) ,
140+ expect . anything ( ) ,
141+ ) ;
109142 } ) ;
110143 } ) ;
144+ } ) ;
0 commit comments