1
1
import * as mockedtimetodisplaynative from './tracing/mockedtimetodisplaynative' ;
2
2
jest . mock ( '../src/js/tracing/timetodisplaynative' , ( ) => mockedtimetodisplaynative ) ;
3
3
4
- import { defaultStackParser } from '@sentry/browser' ;
5
- import type { Envelope , Event , Outcome , Transport , TransportMakeRequestResponse } from '@sentry/types' ;
4
+ import { captureFeedback as captureFeedbackApi , defaultStackParser } from '@sentry/browser' ;
5
+ import type {
6
+ Envelope ,
7
+ Event ,
8
+ Outcome ,
9
+ SendFeedbackParams ,
10
+ Transport ,
11
+ TransportMakeRequestResponse ,
12
+ } from '@sentry/types' ;
6
13
import { rejectedSyncPromise , SentryError } from '@sentry/utils' ;
7
14
import * as RN from 'react-native' ;
8
15
@@ -19,7 +26,6 @@ import {
19
26
envelopeItems ,
20
27
firstArg ,
21
28
getMockSession ,
22
- getMockUserFeedback ,
23
29
getSyncPromiseRejectOnFirstCall ,
24
30
} from './testutils' ;
25
31
@@ -76,6 +82,14 @@ jest.mock(
76
82
} ) ,
77
83
) ;
78
84
85
+ jest . mock ( '@sentry/browser' , ( ) => {
86
+ const actual = jest . requireActual ( '@sentry/browser' ) ;
87
+ return {
88
+ ...actual ,
89
+ captureFeedback : jest . fn ( ) ,
90
+ } ;
91
+ } ) ;
92
+
79
93
const EXAMPLE_DSN = 'https://[email protected] /148053' ;
80
94
81
95
const DEFAULT_OPTIONS : ReactNativeClientOptions = {
@@ -187,15 +201,6 @@ describe('Tests ReactNativeClient', () => {
187
201
expect ( mockTransport . send ) . not . toBeCalled ( ) ;
188
202
} ) ;
189
203
190
- test ( 'captureUserFeedback does not call transport when enabled false' , ( ) => {
191
- const mockTransport = createMockTransport ( ) ;
192
- const client = createDisabledClientWith ( mockTransport ) ;
193
-
194
- client . captureUserFeedback ( getMockUserFeedback ( ) ) ;
195
-
196
- expect ( mockTransport . send ) . not . toBeCalled ( ) ;
197
- } ) ;
198
-
199
204
function createDisabledClientWith ( transport : Transport ) {
200
205
return new ReactNativeClient ( {
201
206
...DEFAULT_OPTIONS ,
@@ -290,34 +295,26 @@ describe('Tests ReactNativeClient', () => {
290
295
} ) ;
291
296
292
297
describe ( 'UserFeedback' , ( ) => {
293
- test ( 'sends UserFeedback to native Layer ' , ( ) => {
298
+ test ( 'sends UserFeedback' , ( ) => {
294
299
const mockTransportSend : jest . Mock = jest . fn ( ( ) => Promise . resolve ( ) ) ;
295
300
const client = new ReactNativeClient ( {
296
301
...DEFAULT_OPTIONS ,
297
302
dsn : EXAMPLE_DSN ,
298
- transport : ( ) => ( {
299
- send : mockTransportSend ,
300
- flush : jest . fn ( ) ,
301
- } ) ,
302
303
} ) ;
304
+ jest . mock ( '@sentry/browser' , ( ) => ( {
305
+ captureFeedback : jest . fn ( ) ,
306
+ } ) ) ;
303
307
304
- client . captureUserFeedback ( {
305
- comments : 'Test Comments' ,
308
+ const feedback : SendFeedbackParams = {
309
+ message : 'Test Comments' ,
306
310
307
311
name : 'Test User' ,
308
- event_id : 'testEvent123' ,
309
- } ) ;
312
+ associatedEventId : 'testEvent123' ,
313
+ } ;
310
314
311
- expect ( mockTransportSend . mock . calls [ 0 ] [ firstArg ] [ envelopeHeader ] . event_id ) . toEqual ( 'testEvent123' ) ;
312
- expect ( mockTransportSend . mock . calls [ 0 ] [ firstArg ] [ envelopeItems ] [ 0 ] [ envelopeItemHeader ] . type ) . toEqual (
313
- 'user_report' ,
314
- ) ;
315
- expect ( mockTransportSend . mock . calls [ 0 ] [ firstArg ] [ envelopeItems ] [ 0 ] [ envelopeItemPayload ] ) . toEqual ( {
316
- comments : 'Test Comments' ,
317
-
318
- name : 'Test User' ,
319
- event_id : 'testEvent123' ,
320
- } ) ;
315
+ client . captureFeedback ( feedback ) ;
316
+
317
+ expect ( captureFeedbackApi ) . toHaveBeenCalledWith ( feedback ) ;
321
318
} ) ;
322
319
} ) ;
323
320
@@ -417,11 +414,6 @@ describe('Tests ReactNativeClient', () => {
417
414
client . captureSession ( getMockSession ( ) ) ;
418
415
expect ( getSdkInfoFrom ( mockTransportSend ) ) . toStrictEqual ( expectedSdkInfo ) ;
419
416
} ) ;
420
-
421
- test ( 'send SdkInfo in the user feedback envelope header' , ( ) => {
422
- client . captureUserFeedback ( getMockUserFeedback ( ) ) ;
423
- expect ( getSdkInfoFrom ( mockTransportSend ) ) . toStrictEqual ( expectedSdkInfo ) ;
424
- } ) ;
425
417
} ) ;
426
418
427
419
describe ( 'event data enhancement' , ( ) => {
0 commit comments