@@ -12,8 +12,7 @@ SENTRY_APM_SAMPLING = 1
12
12
)*/
13
13
const TEST_SPAN_ID = '518999beeceb49af' ;
14
14
15
- const mockSpanFinish = jest . fn ( ) ;
16
- const mockStartChild = jest . fn ( ( spanArgs : SpanContext ) => ( { ...spanArgs , finish : mockSpanFinish } ) ) ;
15
+ const mockStartChild = jest . fn ( ( spanArgs : SpanContext ) => ( { ...spanArgs } ) ) ;
17
16
const TEST_SPAN = {
18
17
spanId : TEST_SPAN_ID ,
19
18
startChild : mockStartChild ,
@@ -57,7 +56,6 @@ beforeEach(() => {
57
56
mockLoggerWarn . mockClear ( ) ;
58
57
mockGetActivitySpan . mockClear ( ) ;
59
58
mockStartChild . mockClear ( ) ;
60
- mockSpanFinish . mockClear ( ) ;
61
59
} ) ;
62
60
63
61
describe ( 'withProfiler' , ( ) => {
@@ -111,26 +109,30 @@ describe('withProfiler', () => {
111
109
} ) ;
112
110
113
111
describe ( 'render span' , ( ) => {
114
- it ( 'does not get created by default ' , ( ) => {
112
+ it ( 'is created on unmount ' , ( ) => {
115
113
const ProfiledComponent = withProfiler ( ( ) => < h1 > Testing</ h1 > ) ;
116
114
expect ( mockStartChild ) . toHaveBeenCalledTimes ( 0 ) ;
117
- render ( < ProfiledComponent /> ) ;
118
- expect ( mockStartChild ) . toHaveBeenCalledTimes ( 0 ) ;
119
- } ) ;
120
115
121
- it ( 'is created when given hasRenderSpan option' , ( ) => {
122
- const ProfiledComponent = withProfiler ( ( ) => < h1 > Testing</ h1 > , { hasRenderSpan : true } ) ;
123
- expect ( mockStartChild ) . toHaveBeenCalledTimes ( 0 ) ;
124
116
const component = render ( < ProfiledComponent /> ) ;
117
+ component . unmount ( ) ;
118
+
125
119
expect ( mockStartChild ) . toHaveBeenCalledTimes ( 1 ) ;
126
- expect ( mockStartChild ) . toHaveBeenLastCalledWith ( {
127
- description : `<${ UNKNOWN_COMPONENT } >` ,
128
- op : 'react.render' ,
129
- } ) ;
120
+ expect ( mockStartChild ) . toHaveBeenLastCalledWith (
121
+ expect . objectContaining ( {
122
+ description : `<${ UNKNOWN_COMPONENT } >` ,
123
+ op : 'react.render' ,
124
+ } ) ,
125
+ ) ;
126
+ } ) ;
130
127
131
- expect ( mockSpanFinish ) . toHaveBeenCalledTimes ( 0 ) ;
128
+ it ( 'is not created if hasRenderSpan is false' , ( ) => {
129
+ const ProfiledComponent = withProfiler ( ( ) => < h1 > Testing</ h1 > , { hasRenderSpan : false } ) ;
130
+ expect ( mockStartChild ) . toHaveBeenCalledTimes ( 0 ) ;
131
+
132
+ const component = render ( < ProfiledComponent /> ) ;
132
133
component . unmount ( ) ;
133
- expect ( mockSpanFinish ) . toHaveBeenCalledTimes ( 1 ) ;
134
+
135
+ expect ( mockStartChild ) . toHaveBeenCalledTimes ( 0 ) ;
134
136
} ) ;
135
137
} ) ;
136
138
@@ -207,25 +209,27 @@ describe('useProfiler()', () => {
207
209
} ) ;
208
210
209
211
describe ( 'render span' , ( ) => {
210
- it ( 'does not get created by default ' , ( ) => {
212
+ it ( 'does not get created when hasRenderSpan is false ' , ( ) => {
211
213
// tslint:disable-next-line: no-void-expression
212
- renderHook ( ( ) => useProfiler ( 'Example' ) ) ;
214
+ const component = renderHook ( ( ) => useProfiler ( 'Example' , { hasRenderSpan : false } ) ) ;
215
+ expect ( mockStartChild ) . toHaveBeenCalledTimes ( 0 ) ;
216
+ component . unmount ( ) ;
213
217
expect ( mockStartChild ) . toHaveBeenCalledTimes ( 0 ) ;
214
218
} ) ;
215
219
216
- it ( 'is created when given hasRenderSpan option ' , ( ) => {
220
+ it ( 'is created by default ' , ( ) => {
217
221
// tslint:disable-next-line: no-void-expression
218
- const component = renderHook ( ( ) => useProfiler ( 'Example' , { hasRenderSpan : true } ) ) ;
219
-
220
- expect ( mockStartChild ) . toHaveBeenCalledTimes ( 1 ) ;
221
- expect ( mockStartChild ) . toHaveBeenLastCalledWith ( {
222
- description : '<Example>' ,
223
- op : 'react.render' ,
224
- } ) ;
222
+ const component = renderHook ( ( ) => useProfiler ( 'Example' ) ) ;
225
223
226
- expect ( mockSpanFinish ) . toHaveBeenCalledTimes ( 0 ) ;
224
+ expect ( mockStartChild ) . toHaveBeenCalledTimes ( 0 ) ;
227
225
component . unmount ( ) ;
228
- expect ( mockSpanFinish ) . toHaveBeenCalledTimes ( 1 ) ;
226
+ expect ( mockStartChild ) . toHaveBeenCalledTimes ( 1 ) ;
227
+ expect ( mockStartChild ) . toHaveBeenLastCalledWith (
228
+ expect . objectContaining ( {
229
+ description : '<Example>' ,
230
+ op : 'react.render' ,
231
+ } ) ,
232
+ ) ;
229
233
} ) ;
230
234
} ) ;
231
235
} ) ;
0 commit comments