@@ -3,7 +3,7 @@ import { rejectedSyncPromise, SentryError } from '@sentry/utils';
3
3
import * as RN from 'react-native' ;
4
4
5
5
import { ReactNativeClient } from '../src/js/client' ;
6
- import { ReactNativeClientOptions , ReactNativeOptions } from '../src/js/options' ;
6
+ import { ReactNativeClientOptions } from '../src/js/options' ;
7
7
import { NativeTransport } from '../src/js/transports/native' ;
8
8
import { SDK_NAME , SDK_PACKAGE_NAME , SDK_VERSION } from '../src/js/version' ;
9
9
import { NATIVE } from '../src/js/wrapper' ;
@@ -66,14 +66,20 @@ jest.mock(
66
66
{ virtual : true }
67
67
) ;
68
68
69
- const DEFAULT_OPTIONS : ReactNativeOptions = {
69
+ const DEFAULT_OPTIONS : ReactNativeClientOptions = {
70
70
enableNative : true ,
71
71
enableNativeCrashHandling : true ,
72
72
enableNativeNagger : true ,
73
73
autoInitializeNativeSdk : true ,
74
74
enableAutoPerformanceTracking : true ,
75
75
enableOutOfMemoryTracking : true ,
76
- patchGlobalPromise : true
76
+ patchGlobalPromise : true ,
77
+ integrations : [ ] ,
78
+ transport : ( ) => ( {
79
+ send : jest . fn ( ) ,
80
+ flush : jest . fn ( ) ,
81
+ } ) ,
82
+ stackParser : jest . fn ( ) . mockReturnValue ( [ ] ) ,
77
83
} ;
78
84
79
85
afterEach ( ( ) => {
@@ -88,7 +94,7 @@ describe('Tests ReactNativeClient', () => {
88
94
...DEFAULT_OPTIONS ,
89
95
dsn : EXAMPLE_DSN ,
90
96
transport : ( ) => new NativeTransport ( )
91
- } as ReactNativeClientOptions ) ;
97
+ } ) ;
92
98
93
99
await expect ( client . eventFromMessage ( 'test' ) ) . resolves . toBeDefined ( ) ;
94
100
// @ts -ignore: Is Mocked
@@ -102,7 +108,7 @@ describe('Tests ReactNativeClient', () => {
102
108
...DEFAULT_OPTIONS ,
103
109
dsn : 'not a dsn' ,
104
110
transport : ( ) => new NativeTransport ( )
105
- } as ReactNativeClientOptions ) ;
111
+ } ) ;
106
112
} catch ( e : any ) {
107
113
expect ( e . message ) . toBe ( 'Invalid Sentry Dsn: not a dsn' ) ;
108
114
}
@@ -114,7 +120,7 @@ describe('Tests ReactNativeClient', () => {
114
120
...DEFAULT_OPTIONS ,
115
121
dsn : undefined ,
116
122
transport : ( ) => new NativeTransport ( )
117
- } as ReactNativeClientOptions ) ;
123
+ } ) ;
118
124
119
125
return expect ( backend . eventFromMessage ( 'test' ) ) . resolves . toBeDefined ( ) ;
120
126
} ) . not . toThrow ( ) ;
@@ -131,7 +137,7 @@ describe('Tests ReactNativeClient', () => {
131
137
...DEFAULT_OPTIONS ,
132
138
dsn : EXAMPLE_DSN ,
133
139
transport : myCustomTransportFn
134
- } as ReactNativeClientOptions ) ;
140
+ } ) ;
135
141
// eslint-disable-next-line @typescript-eslint/unbound-method
136
142
expect ( client . getTransport ( ) ?. flush ) . toBe ( myFlush ) ;
137
143
// eslint-disable-next-line @typescript-eslint/unbound-method
@@ -141,7 +147,7 @@ describe('Tests ReactNativeClient', () => {
141
147
142
148
describe ( 'onReady' , ( ) => {
143
149
test ( 'calls onReady callback with true if Native SDK is initialized' , ( done ) => {
144
- new ReactNativeClient ( {
150
+ new ReactNativeClient ( mockedOptions ( {
145
151
dsn : EXAMPLE_DSN ,
146
152
enableNative : true ,
147
153
onReady : ( { didCallNativeInit } ) => {
@@ -150,11 +156,11 @@ describe('Tests ReactNativeClient', () => {
150
156
done ( ) ;
151
157
} ,
152
158
transport : ( ) => new NativeTransport ( )
153
- } as ReactNativeOptions as ReactNativeClientOptions ) ;
159
+ } ) ) ;
154
160
} ) ;
155
161
156
162
test ( 'calls onReady callback with false if Native SDK was not initialized' , ( done ) => {
157
- new ReactNativeClient ( {
163
+ new ReactNativeClient ( mockedOptions ( {
158
164
dsn : EXAMPLE_DSN ,
159
165
enableNative : false ,
160
166
onReady : ( { didCallNativeInit } ) => {
@@ -163,7 +169,7 @@ describe('Tests ReactNativeClient', () => {
163
169
done ( ) ;
164
170
} ,
165
171
transport : ( ) => new NativeTransport ( )
166
- } as ReactNativeOptions as ReactNativeClientOptions ) ;
172
+ } ) ) ;
167
173
} ) ;
168
174
169
175
test ( 'calls onReady callback with false if Native SDK failed to initialize' , ( done ) => {
@@ -173,7 +179,7 @@ describe('Tests ReactNativeClient', () => {
173
179
throw new Error ( ) ;
174
180
} ) ;
175
181
176
- new ReactNativeClient ( {
182
+ new ReactNativeClient ( mockedOptions ( {
177
183
dsn : EXAMPLE_DSN ,
178
184
enableNative : true ,
179
185
onReady : ( { didCallNativeInit } ) => {
@@ -182,7 +188,7 @@ describe('Tests ReactNativeClient', () => {
182
188
done ( ) ;
183
189
} ,
184
190
transport : ( ) => new NativeTransport ( )
185
- } as ReactNativeOptions as ReactNativeClientOptions ) ;
191
+ } ) ) ;
186
192
} ) ;
187
193
} ) ;
188
194
@@ -195,7 +201,7 @@ describe('Tests ReactNativeClient', () => {
195
201
enableNative : true ,
196
202
transport : ( ) => new NativeTransport ( )
197
203
198
- } as ReactNativeClientOptions ) ;
204
+ } ) ;
199
205
client . nativeCrash ( ) ;
200
206
201
207
expect ( RN . NativeModules . RNSentry . crash ) . toBeCalled ( ) ;
@@ -212,7 +218,7 @@ describe('Tests ReactNativeClient', () => {
212
218
send : mockTransportSend ,
213
219
flush : jest . fn ( ) ,
214
220
} ) ,
215
- } as ReactNativeClientOptions ) ;
221
+ } ) ;
216
222
217
223
client . captureUserFeedback ( {
218
224
comments : 'Test Comments' ,
@@ -247,7 +253,7 @@ describe('Tests ReactNativeClient', () => {
247
253
send : mockTransportSend ,
248
254
flush : jest . fn ( ) ,
249
255
} ) ,
250
- } as ReactNativeClientOptions ) ;
256
+ } ) ;
251
257
} ) ;
252
258
253
259
afterEach ( ( ) => {
@@ -291,7 +297,7 @@ describe('Tests ReactNativeClient', () => {
291
297
send : mockedSend ,
292
298
flush : jest . fn ( ) . mockResolvedValue ( true ) ,
293
299
} ) ;
294
- const client = new ReactNativeClient ( < ReactNativeClientOptions > {
300
+ const client = new ReactNativeClient ( {
295
301
...DEFAULT_OPTIONS ,
296
302
dsn : EXAMPLE_DSN ,
297
303
transport : mockedTransport ,
@@ -317,7 +323,7 @@ describe('Tests ReactNativeClient', () => {
317
323
send : mockedSend ,
318
324
flush : jest . fn ( ) . mockResolvedValue ( true ) ,
319
325
} ) ;
320
- const client = new ReactNativeClient ( < ReactNativeClientOptions > {
326
+ const client = new ReactNativeClient ( {
321
327
...DEFAULT_OPTIONS ,
322
328
dsn : EXAMPLE_DSN ,
323
329
transport : mockedTransport ,
@@ -352,7 +358,7 @@ describe('Tests ReactNativeClient', () => {
352
358
flush : jest . fn ( ) ,
353
359
} ) ,
354
360
sendClientReports : false ,
355
- } as ReactNativeClientOptions ) ;
361
+ } ) ;
356
362
357
363
mockDroppedEvent ( client ) ;
358
364
@@ -371,7 +377,7 @@ describe('Tests ReactNativeClient', () => {
371
377
flush : jest . fn ( ) ,
372
378
} ) ,
373
379
sendClientReports : true ,
374
- } as ReactNativeClientOptions ) ;
380
+ } ) ;
375
381
376
382
mockDroppedEvent ( client ) ;
377
383
@@ -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
client . captureMessage ( 'message_test_value' ) ;
411
417
@@ -423,7 +429,7 @@ describe('Tests ReactNativeClient', () => {
423
429
flush : jest . fn ( ) ,
424
430
} ) ,
425
431
sendClientReports : true ,
426
- } as ReactNativeClientOptions ) ;
432
+ } ) ;
427
433
428
434
mockDroppedEvent ( client ) ;
429
435
@@ -444,7 +450,7 @@ describe('Tests ReactNativeClient', () => {
444
450
flush : jest . fn ( ) ,
445
451
} ) ,
446
452
sendClientReports : true ,
447
- } as ReactNativeClientOptions ) ;
453
+ } ) ;
448
454
449
455
mockDroppedEvent ( client ) ;
450
456
client . captureMessage ( 'message_test_value_1' ) ;
@@ -485,3 +491,15 @@ describe('Tests ReactNativeClient', () => {
485
491
}
486
492
} ) ;
487
493
} ) ;
494
+
495
+ function mockedOptions ( options : Partial < ReactNativeClientOptions > ) : ReactNativeClientOptions {
496
+ return {
497
+ integrations : [ ] ,
498
+ stackParser : jest . fn ( ) . mockReturnValue ( [ ] ) ,
499
+ transport : ( ) => ( {
500
+ send : jest . fn ( ) ,
501
+ flush : jest . fn ( ) ,
502
+ } ) ,
503
+ ...options ,
504
+ } ;
505
+ }
0 commit comments