@@ -4,7 +4,7 @@ import { rejectedSyncPromise, SentryError } from '@sentry/utils';
4
4
import * as RN from 'react-native' ;
5
5
6
6
import { ReactNativeClient } from '../src/js/client' ;
7
- import { ReactNativeClientOptions , ReactNativeOptions } from '../src/js/options' ;
7
+ import { ReactNativeClientOptions } from '../src/js/options' ;
8
8
import { NativeTransport } from '../src/js/transports/native' ;
9
9
import { SDK_NAME , SDK_PACKAGE_NAME , SDK_VERSION } from '../src/js/version' ;
10
10
import { NATIVE } from '../src/js/wrapper' ;
@@ -67,14 +67,20 @@ jest.mock(
67
67
{ virtual : true }
68
68
) ;
69
69
70
- const DEFAULT_OPTIONS : ReactNativeOptions = {
70
+ const DEFAULT_OPTIONS : ReactNativeClientOptions = {
71
71
enableNative : true ,
72
72
enableNativeCrashHandling : true ,
73
73
enableNativeNagger : true ,
74
74
autoInitializeNativeSdk : true ,
75
75
enableAutoPerformanceTracking : true ,
76
76
enableOutOfMemoryTracking : true ,
77
- patchGlobalPromise : true
77
+ patchGlobalPromise : true ,
78
+ integrations : [ ] ,
79
+ transport : ( ) => ( {
80
+ send : jest . fn ( ) ,
81
+ flush : jest . fn ( ) ,
82
+ } ) ,
83
+ stackParser : jest . fn ( ) . mockReturnValue ( [ ] ) ,
78
84
} ;
79
85
80
86
afterEach ( ( ) => {
@@ -89,7 +95,7 @@ describe('Tests ReactNativeClient', () => {
89
95
...DEFAULT_OPTIONS ,
90
96
dsn : EXAMPLE_DSN ,
91
97
transport : ( ) => new NativeTransport ( )
92
- } as ReactNativeClientOptions ) ;
98
+ } ) ;
93
99
94
100
await expect ( client . eventFromMessage ( 'test' ) ) . resolves . toBeDefined ( ) ;
95
101
// @ts -ignore: Is Mocked
@@ -103,7 +109,7 @@ describe('Tests ReactNativeClient', () => {
103
109
...DEFAULT_OPTIONS ,
104
110
dsn : 'not a dsn' ,
105
111
transport : ( ) => new NativeTransport ( )
106
- } as ReactNativeClientOptions ) ;
112
+ } ) ;
107
113
} catch ( e : any ) {
108
114
expect ( e . message ) . toBe ( 'Invalid Sentry Dsn: not a dsn' ) ;
109
115
}
@@ -115,7 +121,7 @@ describe('Tests ReactNativeClient', () => {
115
121
...DEFAULT_OPTIONS ,
116
122
dsn : undefined ,
117
123
transport : ( ) => new NativeTransport ( )
118
- } as ReactNativeClientOptions ) ;
124
+ } ) ;
119
125
120
126
return expect ( backend . eventFromMessage ( 'test' ) ) . resolves . toBeDefined ( ) ;
121
127
} ) . not . toThrow ( ) ;
@@ -132,7 +138,7 @@ describe('Tests ReactNativeClient', () => {
132
138
...DEFAULT_OPTIONS ,
133
139
dsn : EXAMPLE_DSN ,
134
140
transport : myCustomTransportFn
135
- } as ReactNativeClientOptions ) ;
141
+ } ) ;
136
142
// eslint-disable-next-line @typescript-eslint/unbound-method
137
143
expect ( client . getTransport ( ) ?. flush ) . toBe ( myFlush ) ;
138
144
// eslint-disable-next-line @typescript-eslint/unbound-method
@@ -142,7 +148,7 @@ describe('Tests ReactNativeClient', () => {
142
148
143
149
describe ( 'onReady' , ( ) => {
144
150
test ( 'calls onReady callback with true if Native SDK is initialized' , ( done ) => {
145
- new ReactNativeClient ( {
151
+ new ReactNativeClient ( mockedOptions ( {
146
152
dsn : EXAMPLE_DSN ,
147
153
enableNative : true ,
148
154
onReady : ( { didCallNativeInit } ) => {
@@ -151,11 +157,11 @@ describe('Tests ReactNativeClient', () => {
151
157
done ( ) ;
152
158
} ,
153
159
transport : ( ) => new NativeTransport ( )
154
- } as ReactNativeOptions as ReactNativeClientOptions ) ;
160
+ } ) ) ;
155
161
} ) ;
156
162
157
163
test ( 'calls onReady callback with false if Native SDK was not initialized' , ( done ) => {
158
- new ReactNativeClient ( {
164
+ new ReactNativeClient ( mockedOptions ( {
159
165
dsn : EXAMPLE_DSN ,
160
166
enableNative : false ,
161
167
onReady : ( { didCallNativeInit } ) => {
@@ -164,7 +170,7 @@ describe('Tests ReactNativeClient', () => {
164
170
done ( ) ;
165
171
} ,
166
172
transport : ( ) => new NativeTransport ( )
167
- } as ReactNativeOptions as ReactNativeClientOptions ) ;
173
+ } ) ) ;
168
174
} ) ;
169
175
170
176
test ( 'calls onReady callback with false if Native SDK failed to initialize' , ( done ) => {
@@ -174,7 +180,7 @@ describe('Tests ReactNativeClient', () => {
174
180
throw new Error ( ) ;
175
181
} ) ;
176
182
177
- new ReactNativeClient ( {
183
+ new ReactNativeClient ( mockedOptions ( {
178
184
dsn : EXAMPLE_DSN ,
179
185
enableNative : true ,
180
186
onReady : ( { didCallNativeInit } ) => {
@@ -183,7 +189,7 @@ describe('Tests ReactNativeClient', () => {
183
189
done ( ) ;
184
190
} ,
185
191
transport : ( ) => new NativeTransport ( )
186
- } as ReactNativeOptions as ReactNativeClientOptions ) ;
192
+ } ) ) ;
187
193
} ) ;
188
194
} ) ;
189
195
@@ -196,7 +202,7 @@ describe('Tests ReactNativeClient', () => {
196
202
enableNative : true ,
197
203
transport : ( ) => new NativeTransport ( )
198
204
199
- } as ReactNativeClientOptions ) ;
205
+ } ) ;
200
206
client . nativeCrash ( ) ;
201
207
202
208
expect ( RN . NativeModules . RNSentry . crash ) . toBeCalled ( ) ;
@@ -213,7 +219,7 @@ describe('Tests ReactNativeClient', () => {
213
219
send : mockTransportSend ,
214
220
flush : jest . fn ( ) ,
215
221
} ) ,
216
- } as ReactNativeClientOptions ) ;
222
+ } ) ;
217
223
218
224
client . captureUserFeedback ( {
219
225
comments : 'Test Comments' ,
@@ -281,7 +287,7 @@ describe('Tests ReactNativeClient', () => {
281
287
send : mockTransportSend ,
282
288
flush : jest . fn ( ) ,
283
289
} ) ,
284
- } as ReactNativeClientOptions ) ;
290
+ } ) ;
285
291
} ) ;
286
292
287
293
afterEach ( ( ) => {
@@ -325,7 +331,7 @@ describe('Tests ReactNativeClient', () => {
325
331
send : mockedSend ,
326
332
flush : jest . fn ( ) . mockResolvedValue ( true ) ,
327
333
} ) ;
328
- const client = new ReactNativeClient ( < ReactNativeClientOptions > {
334
+ const client = new ReactNativeClient ( {
329
335
...DEFAULT_OPTIONS ,
330
336
dsn : EXAMPLE_DSN ,
331
337
transport : mockedTransport ,
@@ -351,7 +357,7 @@ describe('Tests ReactNativeClient', () => {
351
357
send : mockedSend ,
352
358
flush : jest . fn ( ) . mockResolvedValue ( true ) ,
353
359
} ) ;
354
- const client = new ReactNativeClient ( < ReactNativeClientOptions > {
360
+ const client = new ReactNativeClient ( {
355
361
...DEFAULT_OPTIONS ,
356
362
dsn : EXAMPLE_DSN ,
357
363
transport : mockedTransport ,
@@ -386,7 +392,7 @@ describe('Tests ReactNativeClient', () => {
386
392
flush : jest . fn ( ) ,
387
393
} ) ,
388
394
sendClientReports : false ,
389
- } as ReactNativeClientOptions ) ;
395
+ } ) ;
390
396
391
397
mockDroppedEvent ( client ) ;
392
398
@@ -405,7 +411,7 @@ describe('Tests ReactNativeClient', () => {
405
411
flush : jest . fn ( ) ,
406
412
} ) ,
407
413
sendClientReports : true ,
408
- } as ReactNativeClientOptions ) ;
414
+ } ) ;
409
415
410
416
mockDroppedEvent ( client ) ;
411
417
@@ -439,7 +445,7 @@ describe('Tests ReactNativeClient', () => {
439
445
flush : jest . fn ( ) ,
440
446
} ) ,
441
447
sendClientReports : true ,
442
- } as ReactNativeClientOptions ) ;
448
+ } ) ;
443
449
444
450
client . captureMessage ( 'message_test_value' ) ;
445
451
@@ -457,7 +463,7 @@ describe('Tests ReactNativeClient', () => {
457
463
flush : jest . fn ( ) ,
458
464
} ) ,
459
465
sendClientReports : true ,
460
- } as ReactNativeClientOptions ) ;
466
+ } ) ;
461
467
462
468
mockDroppedEvent ( client ) ;
463
469
@@ -478,7 +484,7 @@ describe('Tests ReactNativeClient', () => {
478
484
flush : jest . fn ( ) ,
479
485
} ) ,
480
486
sendClientReports : true ,
481
- } as ReactNativeClientOptions ) ;
487
+ } ) ;
482
488
483
489
mockDroppedEvent ( client ) ;
484
490
client . captureMessage ( 'message_test_value_1' ) ;
@@ -519,3 +525,15 @@ describe('Tests ReactNativeClient', () => {
519
525
}
520
526
} ) ;
521
527
} ) ;
528
+
529
+ function mockedOptions ( options : Partial < ReactNativeClientOptions > ) : ReactNativeClientOptions {
530
+ return {
531
+ integrations : [ ] ,
532
+ stackParser : jest . fn ( ) . mockReturnValue ( [ ] ) ,
533
+ transport : ( ) => ( {
534
+ send : jest . fn ( ) ,
535
+ flush : jest . fn ( ) ,
536
+ } ) ,
537
+ ...options ,
538
+ } ;
539
+ }
0 commit comments